summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-09-07 12:06:17 +0900
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-09-07 14:23:51 +0900
commitdf9f2e07722fa384cba09e934351e90f0d237009 (patch)
treefec9ee87313645c67c1883f7a0e4bf4282ae0bff /src/lib/ecore
parent743f52a05ba3c5985d9660cec09a4fcc43c55900 (diff)
ecore: Add efl_model_copmosite_selection model
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/Ecore_Eo.h2
-rw-r--r--src/lib/ecore/efl_model_accessor_view.c133
-rw-r--r--src/lib/ecore/efl_model_accessor_view_private.h5
-rw-r--r--src/lib/ecore/efl_model_composite_boolean.c81
-rw-r--r--src/lib/ecore/efl_model_composite_boolean.eo15
-rw-r--r--src/lib/ecore/efl_model_composite_selection.c237
-rw-r--r--src/lib/ecore/efl_model_composite_selection.eo21
-rw-r--r--src/lib/ecore/efl_model_composite_selection_children.eo7
-rw-r--r--src/lib/ecore/efl_model_item.c2
9 files changed, 463 insertions, 40 deletions
diff --git a/src/lib/ecore/Ecore_Eo.h b/src/lib/ecore/Ecore_Eo.h
index 502f6419ec..aadd2ba136 100644
--- a/src/lib/ecore/Ecore_Eo.h
+++ b/src/lib/ecore/Ecore_Eo.h
@@ -115,6 +115,8 @@ EAPI Efl_Future *efl_future_iterator_race(Eina_Iterator *it);
115#include "efl_model_container_item.eo.h" 115#include "efl_model_container_item.eo.h"
116#include "efl_model_composite_boolean.eo.h" 116#include "efl_model_composite_boolean.eo.h"
117#include "efl_model_composite_boolean_children.eo.h" 117#include "efl_model_composite_boolean_children.eo.h"
118#include "efl_model_composite_selection.eo.h"
119#include "efl_model_composite_selection_children.eo.h"
118 120
119/** 121/**
120 * @} 122 * @}
diff --git a/src/lib/ecore/efl_model_accessor_view.c b/src/lib/ecore/efl_model_accessor_view.c
new file mode 100644
index 0000000000..2afe1dc8f3
--- /dev/null
+++ b/src/lib/ecore/efl_model_accessor_view.c
@@ -0,0 +1,133 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eina.h"
6#include "Eo.h"
7
8#include "efl_model_accessor_view_private.h"
9
10typedef struct _Efl_Model_Accessor
11{
12 Eina_Accessor vtable;
13 Eina_Accessor *real_accessor;
14 void *pdata;
15 Efl_Model_Accessor_View_Constructor_Cb cb;
16 Eina_Array *children;
17} Efl_Model_Accessor;
18
19static void
20_efl_model_accessor_setup(Efl_Model_Accessor *acc,
21 Eina_Accessor* real_accessor,
22 Efl_Model_Accessor_View_Constructor_Cb ctor,
23 void* pdata);
24
25static Eina_Bool
26_efl_model_acessor_get_at(Efl_Model_Accessor *acc, unsigned int idx, void **data)
27{
28 void* eo;
29 Eo *p;
30 Eo *child;
31
32 if(eina_accessor_data_get(acc->real_accessor, idx, &eo))
33 {
34 p = eo;
35 child = acc->cb(acc->pdata, p);
36 if(!acc->children)
37 {
38 acc->children = eina_array_new(32);
39 }
40 eina_array_push(acc->children, child);
41 *data = child;
42 return !!*data;
43 }
44 else
45 return EINA_FALSE;
46}
47
48static void *
49_efl_model_acessor_get_container(Efl_Model_Accessor *acc)
50{
51 return eina_accessor_container_get(acc->real_accessor);
52}
53
54static void
55_efl_model_acessor_free(Efl_Model_Accessor *acc)
56{
57 if (acc->real_accessor)
58 {
59 eina_accessor_free(acc->real_accessor);
60 acc->real_accessor = NULL;
61 }
62
63 if(acc->children)
64 {
65 unsigned i;
66 Eina_Array_Iterator iterator;
67 Eo* item;
68
69 EINA_ARRAY_ITER_NEXT(acc->children, i, item, iterator)
70 {
71 efl_del(item);
72 }
73 eina_array_free(acc->children);
74 acc->children = NULL;
75 }
76
77 free(acc);
78}
79
80static Eina_Bool
81_efl_model_acessor_lock(Efl_Model_Accessor *acc)
82{
83 return eina_accessor_lock(acc->real_accessor);
84}
85
86static Eina_Bool
87_efl_model_acessor_unlock(Efl_Model_Accessor *acc)
88{
89 return eina_accessor_unlock(acc->real_accessor);
90}
91
92static Efl_Model_Accessor *
93_efl_model_acessor_clone(Efl_Model_Accessor *acc EINA_UNUSED)
94{
95 Efl_Model_Accessor* accessor = calloc(1, sizeof(Efl_Model_Accessor));
96 _efl_model_accessor_setup(accessor, eina_accessor_clone(acc->real_accessor),
97 acc->cb, acc->pdata);
98 return accessor;
99}
100
101static void
102_efl_model_accessor_setup(Efl_Model_Accessor *acc,
103 Eina_Accessor* real_accessor,
104 Efl_Model_Accessor_View_Constructor_Cb ctor,
105 void* pdata)
106{
107 acc->vtable.version = EINA_ACCESSOR_VERSION;
108 acc->vtable.get_at = FUNC_ACCESSOR_GET_AT(_efl_model_acessor_get_at);
109 acc->vtable.get_container = FUNC_ACCESSOR_GET_CONTAINER(_efl_model_acessor_get_container);
110 acc->vtable.free = FUNC_ACCESSOR_FREE(_efl_model_acessor_free);
111
112 acc->vtable.lock = FUNC_ACCESSOR_LOCK(_efl_model_acessor_lock);
113 acc->vtable.unlock = FUNC_ACCESSOR_LOCK(_efl_model_acessor_unlock);
114
115 acc->vtable.clone = FUNC_ACCESSOR_CLONE(_efl_model_acessor_clone);
116
117 EINA_MAGIC_SET(&acc->vtable, EINA_MAGIC_ACCESSOR);
118
119 acc->real_accessor = real_accessor;
120 acc->cb = ctor;
121 acc->pdata = pdata;
122}
123
124Eina_Accessor* efl_model_accessor_view_new(Eina_Accessor* accessor,
125 Efl_Model_Accessor_View_Constructor_Cb ctor,
126 void* data)
127{
128 Efl_Model_Accessor* acc = calloc(1, sizeof(Efl_Model_Accessor));
129 _efl_model_accessor_setup(acc, accessor, ctor, data);
130 return &acc->vtable;
131}
132
133
diff --git a/src/lib/ecore/efl_model_accessor_view_private.h b/src/lib/ecore/efl_model_accessor_view_private.h
new file mode 100644
index 0000000000..c44f2ec3cb
--- /dev/null
+++ b/src/lib/ecore/efl_model_accessor_view_private.h
@@ -0,0 +1,5 @@
1
2typedef Eo*(*Efl_Model_Accessor_View_Constructor_Cb)(void* data, Eo* child);
3
4Eina_Accessor* efl_model_accessor_view_new(Eina_Accessor* accessor,
5 Efl_Model_Accessor_View_Constructor_Cb constructor, void* data);
diff --git a/src/lib/ecore/efl_model_composite_boolean.c b/src/lib/ecore/efl_model_composite_boolean.c
index 7ec344d05c..62107bbffc 100644
--- a/src/lib/ecore/efl_model_composite_boolean.c
+++ b/src/lib/ecore/efl_model_composite_boolean.c
@@ -18,7 +18,6 @@ typedef struct _Efl_Model_Hash_Value
18typedef struct _Efl_Model_Composite_Boolean_Data 18typedef struct _Efl_Model_Composite_Boolean_Data
19{ 19{
20 Efl_Model *composite_model; 20 Efl_Model *composite_model;
21 Eina_Array *bool_children_cache;
22 Eina_Array *empty_properties; 21 Eina_Array *empty_properties;
23 Eina_Hash *values; // [property_name, Efl_Model_Hash_Value*] 22 Eina_Hash *values; // [property_name, Efl_Model_Hash_Value*]
24} Efl_Model_Composite_Boolean_Data; 23} Efl_Model_Composite_Boolean_Data;
@@ -39,8 +38,14 @@ typedef struct _Efl_Model_Accessor_Slice
39 Efl_Model_Composite_Boolean_Data *parent_pd; 38 Efl_Model_Composite_Boolean_Data *parent_pd;
40 Efl_Promise *promise; 39 Efl_Promise *promise;
41 unsigned int index; 40 unsigned int index;
41 Eina_Array *bool_children_cache;
42} Efl_Model_Accessor_Slice; 42} Efl_Model_Accessor_Slice;
43 43
44static void
45efl_model_accessor_slice_setup(Efl_Model_Accessor_Slice *acc,
46 Efl_Model *parent, Efl_Model_Composite_Boolean_Data *parent_pd, Efl_Promise *promise, int start);
47
48
44static Eina_Value * 49static Eina_Value *
45_value_clone(const Eina_Value *value) 50_value_clone(const Eina_Value *value)
46{ 51{
@@ -66,7 +71,8 @@ _future_error_forward_cb(void *data, Efl_Event const *event)
66static Eina_Bool 71static Eina_Bool
67_bit_get(const unsigned char *bitstream, unsigned int idx) 72_bit_get(const unsigned char *bitstream, unsigned int idx)
68{ 73{
69 return (bitstream[idx / 8] >> (idx % 8)) & 1u; 74 Eina_Bool b = (bitstream[idx / 8] >> (idx % 8)) & 1u;
75 return b;
70} 76}
71 77
72static void 78static void
@@ -160,8 +166,8 @@ _efl_model_composite_boolean_children_efl_model_property_get(Eo *obj EINA_UNUSED
160 Eina_Value *eina_value = eina_value_new(EINA_VALUE_TYPE_UCHAR); 166 Eina_Value *eina_value = eina_value_new(EINA_VALUE_TYPE_UCHAR);
161 if (hv->bits_count <= pd->index) 167 if (hv->bits_count <= pd->index)
162 { 168 {
163 unsigned char f = hv->default_value; 169 unsigned char f = hv->default_value;
164 eina_value_set(eina_value, f); 170 eina_value_set(eina_value, f);
165 } 171 }
166 else 172 else
167 { 173 {
@@ -194,7 +200,7 @@ _efl_model_composite_boolean_children_efl_model_property_set(Eo *obj EINA_UNUSED
194 { 200 {
195 Eina_Bool flag = EINA_FALSE; 201 Eina_Bool flag = EINA_FALSE;
196 202
197 if (eina_value_type_get(value) == EINA_VALUE_TYPE_UCHAR) 203 if (eina_value_type_get(value) != EINA_VALUE_TYPE_UCHAR)
198 { 204 {
199 efl_promise_failed_set(promise, EFL_MODEL_ERROR_INCORRECT_VALUE); 205 efl_promise_failed_set(promise, EFL_MODEL_ERROR_INCORRECT_VALUE);
200 return rfuture; 206 return rfuture;
@@ -285,7 +291,7 @@ static Eina_Bool
285efl_model_acessor_slice_get_at(Efl_Model_Accessor_Slice *acc, unsigned int idx, void **data) 291efl_model_acessor_slice_get_at(Efl_Model_Accessor_Slice *acc, unsigned int idx, void **data)
286{ 292{
287 Efl_Model *child_bool; 293 Efl_Model *child_bool;
288 Eina_Array *children_cache = acc->parent_pd->bool_children_cache; 294 Eina_Array *children_cache = acc->bool_children_cache;
289 295
290 /* NOTE: Efl.Model.Composite.Boolean must alloc the cache with the correct size 296 /* NOTE: Efl.Model.Composite.Boolean must alloc the cache with the correct size
291 and NULL initialized. */ 297 and NULL initialized. */
@@ -295,7 +301,7 @@ efl_model_acessor_slice_get_at(Efl_Model_Accessor_Slice *acc, unsigned int idx,
295 return EINA_FALSE; 301 return EINA_FALSE;
296 } 302 }
297 303
298 child_bool = eina_array_data_get(children_cache, idx); 304 child_bool = eina_array_data_get(children_cache, acc->index + idx);
299 305
300 if (!child_bool) 306 if (!child_bool)
301 { 307 {
@@ -306,13 +312,13 @@ efl_model_acessor_slice_get_at(Efl_Model_Accessor_Slice *acc, unsigned int idx,
306 312
307 if (child) 313 if (child)
308 { 314 {
309 Efl_Model_Composite_Boolean_Children_Data *pd; 315 Efl_Model_Composite_Boolean_Children_Data *cpd;
310 child_bool = efl_add(EFL_MODEL_COMPOSITE_BOOLEAN_CHILDREN_CLASS, NULL); 316 child_bool = efl_add(EFL_MODEL_COMPOSITE_BOOLEAN_CHILDREN_CLASS, NULL);
311 pd = efl_data_scope_get(child_bool, EFL_MODEL_COMPOSITE_BOOLEAN_CHILDREN_CLASS); 317 cpd = efl_data_scope_get(child_bool, EFL_MODEL_COMPOSITE_BOOLEAN_CHILDREN_CLASS);
312 318
313 pd->parent_pd = acc->parent_pd; 319 cpd->parent_pd = acc->parent_pd;
314 pd->composite_child = efl_ref(child); 320 cpd->composite_child = efl_ref(child);
315 pd->index = acc->index++; 321 cpd->index = acc->index + idx;
316 322
317 eina_array_data_set(children_cache, idx, child_bool); 323 eina_array_data_set(children_cache, idx, child_bool);
318 } 324 }
@@ -331,9 +337,15 @@ efl_model_acessor_slice_get_container(Efl_Model_Accessor_Slice *acc)
331static void 337static void
332efl_model_acessor_slice_free(Efl_Model_Accessor_Slice *acc) 338efl_model_acessor_slice_free(Efl_Model_Accessor_Slice *acc)
333{ 339{
334 if (acc->real_accessor) 340 if (acc->bool_children_cache)
341 {
342 _bool_children_cache_array_free(acc->bool_children_cache);
343 acc->bool_children_cache = NULL;
344 }
345
346 if (acc->real_accessor)
335 { 347 {
336 eina_accessor_free(acc->real_accessor); 348 /* eina_accessor_free(acc->real_accessor); */
337 acc->real_accessor = NULL; 349 acc->real_accessor = NULL;
338 } 350 }
339 351
@@ -364,12 +376,31 @@ efl_model_acessor_slice_unlock(Efl_Model_Accessor_Slice *acc)
364static Efl_Model_Accessor_Slice * 376static Efl_Model_Accessor_Slice *
365efl_model_acessor_slice_clone(Efl_Model_Accessor_Slice *acc EINA_UNUSED) 377efl_model_acessor_slice_clone(Efl_Model_Accessor_Slice *acc EINA_UNUSED)
366{ 378{
367 return NULL; 379 Efl_Model_Accessor_Slice* new_accessor = calloc(1, sizeof(Efl_Model_Accessor_Slice));
380 Eina_Array* children_cache;
381 unsigned i;
382 unsigned children_count = eina_array_count(acc->bool_children_cache);
383
384 efl_model_accessor_slice_setup(new_accessor, acc->parent, acc->parent_pd, NULL
385 , acc->index);
386 new_accessor->real_accessor = eina_accessor_clone(acc->real_accessor);
387
388 children_cache = eina_array_new(children_count);
389 for (i = 0 ; i < children_count; ++i)
390 {
391 // NOTE: eina_array_push do not accept NULL
392 eina_array_push(children_cache, (void*)0x01);
393 eina_array_data_set(children_cache, i, NULL);
394 }
395
396 new_accessor->bool_children_cache = children_cache;
397
398 return new_accessor;
368} 399}
369 400
370static void 401static void
371efl_model_accessor_slice_setup(Efl_Model_Accessor_Slice *acc, 402efl_model_accessor_slice_setup(Efl_Model_Accessor_Slice *acc,
372 Efl_Model *parent, Efl_Model_Composite_Boolean_Data *parent_pd, Efl_Promise *promise) 403 Efl_Model *parent, Efl_Model_Composite_Boolean_Data *parent_pd, Efl_Promise *promise, int start)
373{ 404{
374 acc->vtable.version = EINA_ACCESSOR_VERSION; 405 acc->vtable.version = EINA_ACCESSOR_VERSION;
375 acc->vtable.get_at = FUNC_ACCESSOR_GET_AT(efl_model_acessor_slice_get_at); 406 acc->vtable.get_at = FUNC_ACCESSOR_GET_AT(efl_model_acessor_slice_get_at);
@@ -386,6 +417,7 @@ efl_model_accessor_slice_setup(Efl_Model_Accessor_Slice *acc,
386 acc->parent = efl_ref(parent); 417 acc->parent = efl_ref(parent);
387 acc->parent_pd = parent_pd; 418 acc->parent_pd = parent_pd;
388 acc->promise = promise; 419 acc->promise = promise;
420 acc->index = start;
389} 421}
390 422
391static void 423static void
@@ -413,8 +445,8 @@ _efl_model_composite_boolean_slice_then_cb(void *data, Efl_Event const *event)
413 Eina_Array *children_cache; 445 Eina_Array *children_cache;
414 unsigned int i; 446 unsigned int i;
415 447
416 if (slice_acc->parent_pd->bool_children_cache) 448 if (slice_acc->bool_children_cache)
417 _bool_children_cache_array_free(slice_acc->parent_pd->bool_children_cache); 449 _bool_children_cache_array_free(slice_acc->bool_children_cache);
418 450
419 children_cache = eina_array_new(*children_count); 451 children_cache = eina_array_new(*children_count);
420 for (i = 0 ; i < *children_count; ++i) 452 for (i = 0 ; i < *children_count; ++i)
@@ -424,7 +456,7 @@ _efl_model_composite_boolean_slice_then_cb(void *data, Efl_Event const *event)
424 eina_array_data_set(children_cache, i, NULL); 456 eina_array_data_set(children_cache, i, NULL);
425 } 457 }
426 458
427 slice_acc->parent_pd->bool_children_cache = children_cache; 459 slice_acc->bool_children_cache = children_cache;
428 460
429 efl_promise_value_set(slice_acc->promise, slice_acc, (Eina_Free_Cb)&eina_accessor_free); 461 efl_promise_value_set(slice_acc->promise, slice_acc, (Eina_Free_Cb)&eina_accessor_free);
430 } 462 }
@@ -460,11 +492,6 @@ efl_model_hash_value_free(void *p)
460static void 492static void
461_composite_model_data_reset(Efl_Model_Composite_Boolean_Data *pd) 493_composite_model_data_reset(Efl_Model_Composite_Boolean_Data *pd)
462{ 494{
463 if (pd->bool_children_cache)
464 {
465 _bool_children_cache_array_free(pd->bool_children_cache);
466 pd->bool_children_cache = NULL;
467 }
468 495
469 if (pd->composite_model) 496 if (pd->composite_model)
470 { 497 {
@@ -494,7 +521,7 @@ _efl_model_composite_boolean_efl_object_destructor(Eo *obj, Efl_Model_Composite_
494} 521}
495 522
496static void 523static void
497_efl_model_composite_boolean_composite_model_set(Eo *obj EINA_UNUSED, 524_efl_model_composite_boolean_efl_ui_view_model_set(Eo *obj EINA_UNUSED,
498 Efl_Model_Composite_Boolean_Data *pd, Efl_Model *model) 525 Efl_Model_Composite_Boolean_Data *pd, Efl_Model *model)
499{ 526{
500 if (pd->composite_model) 527 if (pd->composite_model)
@@ -506,7 +533,7 @@ _efl_model_composite_boolean_composite_model_set(Eo *obj EINA_UNUSED,
506} 533}
507 534
508static Efl_Model * 535static Efl_Model *
509_efl_model_composite_boolean_composite_model_get(Eo *obj EINA_UNUSED, Efl_Model_Composite_Boolean_Data *pd) 536_efl_model_composite_boolean_efl_ui_view_model_get(Eo *obj EINA_UNUSED, Efl_Model_Composite_Boolean_Data *pd)
510{ 537{
511 return pd->composite_model; 538 return pd->composite_model;
512} 539}
@@ -586,7 +613,7 @@ _efl_model_composite_boolean_efl_model_children_slice_get(Eo *obj, Efl_Model_Com
586 composite_future = efl_future_all(futures[0], futures[1]); 613 composite_future = efl_future_all(futures[0], futures[1]);
587 614
588 accessor = calloc(1, sizeof(Efl_Model_Accessor_Slice)); 615 accessor = calloc(1, sizeof(Efl_Model_Accessor_Slice));
589 efl_model_accessor_slice_setup(accessor, obj, pd, promise); 616 efl_model_accessor_slice_setup(accessor, obj, pd, promise, start);
590 617
591 efl_future_then(composite_future, &_efl_model_composite_boolean_slice_then_cb, 618 efl_future_then(composite_future, &_efl_model_composite_boolean_slice_then_cb,
592 &_efl_model_composite_boolean_slice_error_cb, NULL, accessor); 619 &_efl_model_composite_boolean_slice_error_cb, NULL, accessor);
diff --git a/src/lib/ecore/efl_model_composite_boolean.eo b/src/lib/ecore/efl_model_composite_boolean.eo
index cdca17e998..bb7eacbb11 100644
--- a/src/lib/ecore/efl_model_composite_boolean.eo
+++ b/src/lib/ecore/efl_model_composite_boolean.eo
@@ -1,17 +1,7 @@
1class Efl.Model.Composite.Boolean (Efl.Object, Efl.Model) 1class Efl.Model.Composite.Boolean (Efl.Object, Efl.Model, Efl.Ui.View)
2{ 2{
3 [[Efl model composite boolean class]] 3 [[Efl model composite boolean class]]
4 methods { 4 methods {
5 @property composite_model {
6 [[Composite model]]
7 set {
8 }
9 get {
10 }
11 values {
12 model: Efl.Model; [[Efl model]]
13 }
14 }
15 property_add { 5 property_add {
16 [[Adds property]] 6 [[Adds property]]
17 params { 7 params {
@@ -29,9 +19,10 @@ class Efl.Model.Composite.Boolean (Efl.Object, Efl.Model)
29 Efl.Model.children_count_get; 19 Efl.Model.children_count_get;
30 Efl.Model.child_add; 20 Efl.Model.child_add;
31 Efl.Model.child_del; 21 Efl.Model.child_del;
22 Efl.Ui.View.model { set; get; }
32 } 23 }
33 constructors { 24 constructors {
34 .composite_model; 25 Efl.Ui.View.model;
35 .property_add @optional; 26 .property_add @optional;
36 } 27 }
37} 28}
diff --git a/src/lib/ecore/efl_model_composite_selection.c b/src/lib/ecore/efl_model_composite_selection.c
new file mode 100644
index 0000000000..8311f1c7b5
--- /dev/null
+++ b/src/lib/ecore/efl_model_composite_selection.c
@@ -0,0 +1,237 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eina.h"
6#include "Efl.h"
7#include <Ecore.h>
8#include "Eo.h"
9
10#include "efl_model_composite_selection.eo.h"
11#include "efl_model_accessor_view_private.h"
12
13typedef struct _Efl_Model_Composite_Selection_Data
14{
15 Efl_Model_Composite_Selection* obj;
16 struct {
17 Efl_Model* selected_child;
18 } exclusive_data;
19 Eina_Bool is_exclusive;
20
21} Efl_Model_Composite_Selection_Data;
22
23typedef struct _Efl_Model_Composite_Selection_Children_Data
24{
25 Efl_Model_Composite_Selection_Data* pd;
26} Efl_Model_Composite_Selection_Children_Data;
27
28static Eo*
29_efl_model_composite_selection_efl_object_constructor(Eo *obj,
30 Efl_Model_Composite_Selection_Data *pd EINA_UNUSED)
31{
32 efl_constructor(efl_super(obj, EFL_MODEL_COMPOSITE_SELECTION_CLASS));
33 efl_model_composite_boolean_property_add(obj, "selected", EINA_FALSE);
34 pd->obj = obj;
35 return obj;
36}
37
38/***************************/
39static void _select_property_failed(void* data, Efl_Event const* event)
40{
41 Efl_Promise* promise = data;
42 Efl_Future_Event_Failure* fail = event->info;
43 efl_promise_failed_set(promise, fail->error);
44 efl_unref(promise);
45}
46
47static void _select_property_then(void* data, Efl_Event const* event EINA_UNUSED)
48{
49 Efl_Promise* promise = data;
50 Eina_Value* v = eina_value_new(EINA_VALUE_TYPE_UCHAR);
51 eina_value_set(v, EINA_TRUE);
52 efl_promise_value_set(promise, v, (Eina_Free_Cb)&eina_value_free);
53 efl_unref(promise);
54}
55
56static void _select_slice_then(void* data EINA_UNUSED, Efl_Event const* event)
57{
58 Efl_Future_Event_Success* success = event->info;
59 Eina_Accessor* accessor = eina_accessor_clone(success->value);
60 Eina_Value value;
61 Efl_Model* child;
62
63 eina_accessor_data_get(accessor, 0, (void**)&child);
64
65 eina_value_setup(&value, EINA_VALUE_TYPE_UCHAR);
66 eina_value_set(&value, EINA_TRUE);
67
68 efl_future_then(efl_model_property_set(child, "selected", &value),
69 _select_property_then, _select_property_failed, NULL, efl_ref(success->next));
70}
71
72static void _select_error(void* data EINA_UNUSED, Efl_Event const* event)
73{
74 Efl_Future_Event_Failure* fail = event->info;
75 efl_promise_failed_set(fail->next, fail->error);
76}
77
78/***************************/
79
80static Efl_Future*
81_efl_model_composite_selection_select(Eo *obj,
82 Efl_Model_Composite_Selection_Data *pd, int idx)
83{
84 return efl_future_then(efl_model_children_slice_get(obj, idx, 1),
85 &_select_slice_then,
86 &_select_error,
87 NULL, pd);
88}
89
90static void
91_efl_model_composite_selection_exclusive_selection_set(Eo *obj EINA_UNUSED,
92 Efl_Model_Composite_Selection_Data *pd, Eina_Bool exclusive)
93{
94 pd->is_exclusive = exclusive;
95}
96
97static Eina_Bool
98_efl_model_composite_selection_exclusive_selection_get(Eo *obj EINA_UNUSED,
99 Efl_Model_Composite_Selection_Data *pd)
100{
101 return pd->is_exclusive;
102}
103
104static void
105_exclusive_future_link_then_cb(void* data, Efl_Event const* event)
106{
107 Efl_Future_Event_Success *success = event->info;
108 efl_promise_value_set(data, success->value, NULL); // We would need to move the value
109 // Needs to set exclusive_child
110 efl_unref(data);
111}
112
113static void
114_exclusive_future_link_failed(void* data, Efl_Event const* event)
115{
116 Efl_Future_Event_Failure *failed = event->info;
117 efl_promise_failed_set(data, failed->error);
118 efl_unref(data);
119}
120
121static void
122_exclusive_unselected_then_cb(void* data, Efl_Event const* event)
123{
124 Efl_Future_Event_Success *success = event->info;
125 Eina_Value* true_value = eina_value_new(EINA_VALUE_TYPE_UCHAR);
126 eina_value_set(true_value, EINA_TRUE);
127 efl_future_then(efl_model_property_set(data, "selected", true_value),
128 _exclusive_future_link_then_cb, _exclusive_future_link_failed,
129 NULL, efl_ref(success->next));
130 efl_unref(data);
131}
132
133static void
134_exclusive_unselected_failed(void* data, Efl_Event const* event)
135{
136 Efl_Future_Event_Failure *failed = event->info;
137 efl_promise_failed_set(data, failed->error);
138 efl_unref(data);
139}
140
141static Efl_Future *
142_efl_model_composite_selection_children_efl_model_property_set(Eo *obj EINA_UNUSED,
143 Efl_Model_Composite_Selection_Children_Data *pd, const char *property, const Eina_Value *value)
144{
145 if(!strcmp("selected", property))
146 {
147 unsigned long v = EINA_FALSE;
148 if(eina_value_type_get(value) != EINA_VALUE_TYPE_ULONG)
149 {
150 Eina_Value to;
151 eina_value_setup(&to, EINA_VALUE_TYPE_ULONG);
152 if(eina_value_convert(value, &to))
153 eina_value_get(&to, &v);
154 eina_value_flush(&to);
155 }
156 else
157 eina_value_get(value, &v);
158
159 if(v && pd->pd->is_exclusive)
160 {
161 if(pd->pd->exclusive_data.selected_child)
162 {
163 // unset current selected
164 // set this child as current
165 // bookkeep this child as current selection
166 // return with future for this asynchronous task
167 Eina_Value* false_value = eina_value_new(EINA_VALUE_TYPE_UCHAR);
168 eina_value_set(false_value, EINA_FALSE);
169 return
170 efl_future_then(efl_model_property_set
171 (pd->pd->exclusive_data.selected_child,
172 property, false_value),
173 _exclusive_unselected_then_cb,
174 _exclusive_unselected_failed, NULL,
175 efl_ref(obj));
176 }
177 else
178 {
179 Efl_Promise *promise = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
180 Efl_Future *rfuture = efl_promise_future_get(promise);
181 Eina_Value* true_value = eina_value_new(EINA_VALUE_TYPE_UCHAR);
182 eina_value_set(true_value, EINA_TRUE);
183 efl_future_then(efl_model_property_set
184 (efl_super(obj, EFL_MODEL_COMPOSITE_SELECTION_CHILDREN_CLASS),
185 "selected", true_value),
186 _exclusive_future_link_then_cb, _exclusive_future_link_failed,
187 NULL, efl_ref(promise));
188 return rfuture;
189 }
190 }
191 else
192 {
193
194 }
195 }
196
197 return efl_model_property_set(efl_super(obj, EFL_MODEL_COMPOSITE_SELECTION_CHILDREN_CLASS),
198 property, value);
199}
200
201static Eo* _construct_children(void* pdata, Eo* child)
202{
203 Efl_Model_Composite_Selection_Data* pd = pdata;
204 Eo* new_child = efl_add(EFL_MODEL_COMPOSITE_SELECTION_CHILDREN_CLASS, NULL);
205 Efl_Model_Composite_Selection_Children_Data* data = efl_data_scope_get
206 (new_child, EFL_MODEL_COMPOSITE_SELECTION_CHILDREN_CLASS);
207 data->pd = pd;
208 efl_composite_attach(new_child, efl_ref(child));
209 return new_child;
210}
211
212static void _composited_children_slice_get_then(void* data, Efl_Event const* event)
213{
214 Efl_Future_Event_Success* success = event->info;
215 Eina_Accessor* accessor = success->value;
216 efl_promise_value_set(success->next,
217 efl_model_accessor_view_new(eina_accessor_clone(accessor), &_construct_children,
218 data),
219 (Eina_Free_Cb)&eina_accessor_free);
220}
221static void _composited_children_slice_get_fail(void* data EINA_UNUSED, Efl_Event const* event)
222{
223 Efl_Future_Event_Failure* failure = event->info;
224 efl_promise_failed_set(failure->next, failure->error);
225}
226
227static Efl_Future *
228_efl_model_composite_selection_efl_model_children_slice_get(Eo *obj, Efl_Model_Composite_Selection_Data *pd, unsigned int start, unsigned int count)
229{
230 Efl_Future* composited_future = efl_model_children_slice_get
231 (efl_super(obj, EFL_MODEL_COMPOSITE_SELECTION_CLASS),start, count);
232 return efl_future_then(composited_future, &_composited_children_slice_get_then,
233 &_composited_children_slice_get_fail, NULL, pd);
234}
235
236#include "efl_model_composite_selection.eo.c"
237#include "efl_model_composite_selection_children.eo.c"
diff --git a/src/lib/ecore/efl_model_composite_selection.eo b/src/lib/ecore/efl_model_composite_selection.eo
new file mode 100644
index 0000000000..bccf0070ad
--- /dev/null
+++ b/src/lib/ecore/efl_model_composite_selection.eo
@@ -0,0 +1,21 @@
1class Efl.Model.Composite.Selection (Efl.Model.Composite.Boolean)
2{
3 [[Efl model composite selection class]]
4 methods {
5 select {
6 params {
7 idx: int;
8 }
9 return: future<eina.value>;
10 }
11 @property exclusive_selection {
12 values {
13 exclusive: bool;
14 }
15 }
16 }
17 implements {
18 Efl.Object.constructor;
19 Efl.Model.children_slice_get;
20 }
21}
diff --git a/src/lib/ecore/efl_model_composite_selection_children.eo b/src/lib/ecore/efl_model_composite_selection_children.eo
new file mode 100644
index 0000000000..2ea5c950ef
--- /dev/null
+++ b/src/lib/ecore/efl_model_composite_selection_children.eo
@@ -0,0 +1,7 @@
1class Efl.Model.Composite.Selection.Children (Efl.Object, Efl.Model)
2{
3 [[Efl model composite selection children class]]
4 implements {
5 Efl.Model.property_set;
6 }
7}
diff --git a/src/lib/ecore/efl_model_item.c b/src/lib/ecore/efl_model_item.c
index 5f61ee79e9..8afc0a77a4 100644
--- a/src/lib/ecore/efl_model_item.c
+++ b/src/lib/ecore/efl_model_item.c
@@ -169,9 +169,9 @@ _efl_model_item_efl_model_child_add(Eo *obj, Efl_Model_Item_Data *sd)
169 eina_error_set(EFL_MODEL_ERROR_UNKNOWN); 169 eina_error_set(EFL_MODEL_ERROR_UNKNOWN);
170 return NULL; 170 return NULL;
171 } 171 }
172 cevt.index = eina_list_count(sd->children);
172 sd->children = eina_list_append(sd->children, child); 173 sd->children = eina_list_append(sd->children, child);
173 cevt.child = child; 174 cevt.child = child;
174 cevt.index = eina_list_count(sd->children);
175 efl_event_callback_call(obj, EFL_MODEL_EVENT_CHILD_ADDED, &cevt); 175 efl_event_callback_call(obj, EFL_MODEL_EVENT_CHILD_ADDED, &cevt);
176 efl_event_callback_call(obj, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, &cevt.index); 176 efl_event_callback_call(obj, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, &cevt.index);
177 return child; 177 return child;