Efl_Ui: Move elementary and change namespace Ui for ui related models

Summary:
Select and View is ui characteristic features,
so Efl_Select_Model and Efl_View_Model move to elementary from ecore
seems more natural.

namespace also should changed to Efl.Ui as it's right place.

Test Plan: run the test while building it

Reviewers: cedric, felipealmeida, bu5hm4n, zmike, lauromoura

Reviewed By: zmike

Subscribers: #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D9820
This commit is contained in:
SangHyeon Jade Lee 2019-09-04 11:07:37 -04:00 committed by Mike Blumenkrantz
parent 8b49bdb830
commit 4e379f5db4
24 changed files with 410 additions and 393 deletions

View File

@ -74,7 +74,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
Efl_Ui_Factory *factory; Efl_Ui_Factory *factory;
Evas_Object *win, *li; Evas_Object *win, *li;
Eo *model; Eo *model;
Efl_Select_Model *selmodel; Efl_Ui_Select_Model *selmodel;
win = elm_win_util_standard_add("list_view", "List_View"); win = elm_win_util_standard_add("list_view", "List_View");
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
@ -82,7 +82,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
elm_win_autodel_set(win, EINA_TRUE); elm_win_autodel_set(win, EINA_TRUE);
model = _make_model(win); model = _make_model(win);
selmodel = efl_add(EFL_SELECT_MODEL_CLASS, efl_main_loop_get() selmodel = efl_add(EFL_UI_SELECT_MODEL_CLASS, efl_main_loop_get()
, efl_ui_view_model_set(efl_added, model) , efl_ui_view_model_set(efl_added, model)
); );

View File

@ -125,9 +125,7 @@ EAPI Eo *efl_main_loop_get(void);
#include "efl_container_model.eo.h" #include "efl_container_model.eo.h"
#include "efl_composite_model.eo.h" #include "efl_composite_model.eo.h"
#include "efl_boolean_model.eo.h" #include "efl_boolean_model.eo.h"
#include "efl_select_model.eo.h"
#include "efl_filter_model.eo.h" #include "efl_filter_model.eo.h"
#include "efl_view_model.eo.h"
/** /**
* @} * @}

View File

@ -59,6 +59,76 @@ efl_model_list_value_get(Eina_List *childrens,
return v; return v;
} }
#define EFL_COMPOSITE_MODEL_CHILD_INDEX "child.index"
#define EFL_COMPOSITE_MODEL_PROPERTIES(name, dyn, sta, ...) \
EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(name, NULL, NULL, (dyn), sta, ##__VA_ARGS__)
#define EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(name, obj, klass, dyn, ...) \
Eina_Iterator *name; \
do \
{ \
static const char *static_props__[] = { \
__VA_ARGS__ \
}; \
name = _efl_composite_model_properties_mix( \
((obj) ? efl_model_properties_get(efl_super((obj), (klass))) : NULL), \
(dyn), \
EINA_C_ARRAY_ITERATOR_NEW(static_props__)); \
} \
while (0)
static inline Eina_Iterator *
_efl_composite_model_properties_mix(Eina_Iterator *super, Eina_Iterator *dyn, Eina_Iterator *sta)
{
Eina_Iterator *its[3];
int i = 0;
if (sta) its[i++] = sta;
if (dyn) its[i++] = dyn;
if (super) its[i++] = super;
switch (i)
{
case 1: return its[0];
case 2: return eina_multi_iterator_new(its[0], its[1]);
case 3: return eina_multi_iterator_new(its[0], its[1], its[2]);
default: return NULL;
};
}
#define EFL_COMPOSITE_LOOKUP_RETURN(Remember, Parent, View, Base) \
Efl_Model *Remember; \
char buf[1024]; \
\
snprintf(buf, sizeof (buf), Base"-%p", Parent); \
Remember = efl_key_wref_get(View, buf); \
if (Remember) \
{ \
efl_ref(Remember); \
return Remember; \
}
#define EFL_COMPOSITE_REMEMBER_RETURN(Remember, View) \
efl_key_wref_set(View, buf, Remember); \
return Remember;
static inline Efl_Model *
_efl_composite_lookup(const Efl_Class *self, Eo *parent, Efl_Model *view, unsigned int index)
{
EFL_COMPOSITE_LOOKUP_RETURN(remember, parent, view, "_efl.composite_model");
remember = efl_add_ref(self, parent,
efl_ui_view_model_set(efl_added, view),
efl_composite_model_index_set(efl_added, index),
efl_loop_model_volatile_make(efl_added));
if (!remember) return NULL;
EFL_COMPOSITE_REMEMBER_RETURN(remember, view);
}
#undef EAPI #undef EAPI
#define EAPI #define EAPI

View File

@ -4,7 +4,7 @@
#include <Efl_Core.h> #include <Efl_Core.h>
#include "efl_composite_model_private.h" #include "ecore_internal.h"
typedef struct _Efl_Boolean_Model_Data Efl_Boolean_Model_Data; typedef struct _Efl_Boolean_Model_Data Efl_Boolean_Model_Data;
typedef struct _Efl_Boolean_Model_Value Efl_Boolean_Model_Value; typedef struct _Efl_Boolean_Model_Value Efl_Boolean_Model_Value;

View File

@ -7,8 +7,6 @@
#include <Ecore.h> #include <Ecore.h>
#include "ecore_private.h" #include "ecore_private.h"
#include "efl_composite_model_private.h"
#include "efl_composite_model.eo.h" #include "efl_composite_model.eo.h"
typedef struct _Efl_Composite_Model_Data Efl_Composite_Model_Data; typedef struct _Efl_Composite_Model_Data Efl_Composite_Model_Data;

View File

@ -1,74 +0,0 @@
#ifndef EFL_COMPOSITE_MODEL_PRIVATE_H_
# define EFL_COMPOSITE_MODEL_PRIVATE_H_
#define EFL_COMPOSITE_MODEL_CHILD_INDEX "child.index"
#define EFL_COMPOSITE_MODEL_PROPERTIES(name, dyn, sta, ...) \
EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(name, NULL, NULL, (dyn), sta, ##__VA_ARGS__)
#define EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(name, obj, klass, dyn, ...) \
Eina_Iterator *name; \
do \
{ \
static const char *static_props__[] = { \
__VA_ARGS__ \
}; \
name = _efl_composite_model_properties_mix( \
((obj) ? efl_model_properties_get(efl_super((obj), (klass))) : NULL), \
(dyn), \
EINA_C_ARRAY_ITERATOR_NEW(static_props__)); \
} \
while (0)
static inline Eina_Iterator *
_efl_composite_model_properties_mix(Eina_Iterator *super, Eina_Iterator *dyn, Eina_Iterator *sta)
{
Eina_Iterator *its[3];
int i = 0;
if (sta) its[i++] = sta;
if (dyn) its[i++] = dyn;
if (super) its[i++] = super;
switch (i)
{
case 1: return its[0];
case 2: return eina_multi_iterator_new(its[0], its[1]);
case 3: return eina_multi_iterator_new(its[0], its[1], its[2]);
default: return NULL;
};
}
#define EFL_COMPOSITE_LOOKUP_RETURN(Remember, Parent, View, Base) \
Efl_Model *Remember; \
char buf[1024]; \
\
snprintf(buf, sizeof (buf), Base"-%p", Parent); \
Remember = efl_key_wref_get(View, buf); \
if (Remember) \
{ \
efl_ref(Remember); \
return Remember; \
}
#define EFL_COMPOSITE_REMEMBER_RETURN(Remember, View) \
efl_key_wref_set(View, buf, Remember); \
return Remember;
static inline Efl_Model *
_efl_composite_lookup(const Efl_Class *self, Eo *parent, Efl_Model *view, unsigned int index)
{
EFL_COMPOSITE_LOOKUP_RETURN(remember, parent, view, "_efl.composite_model");
remember = efl_add_ref(self, parent,
efl_ui_view_model_set(efl_added, view),
efl_composite_model_index_set(efl_added, index),
efl_loop_model_volatile_make(efl_added));
if (!remember) return NULL;
EFL_COMPOSITE_REMEMBER_RETURN(remember, view);
}
#endif

View File

@ -8,7 +8,6 @@
#include <Ecore.h> #include <Ecore.h>
#include "ecore_internal.h" #include "ecore_internal.h"
#include "efl_composite_model_private.h"
typedef struct _Efl_Container_Property_Data Efl_Container_Property_Data; typedef struct _Efl_Container_Property_Data Efl_Container_Property_Data;
typedef struct _Efl_Container_Model_Data Efl_Container_Model_Data; typedef struct _Efl_Container_Model_Data Efl_Container_Model_Data;

View File

@ -4,7 +4,7 @@
#include <Efl_Core.h> #include <Efl_Core.h>
#include "efl_composite_model_private.h" #include "ecore_internal.h"
typedef struct _Efl_Filter_Model_Mapping Efl_Filter_Model_Mapping; typedef struct _Efl_Filter_Model_Mapping Efl_Filter_Model_Mapping;
struct _Efl_Filter_Model_Mapping struct _Efl_Filter_Model_Mapping

View File

@ -59,9 +59,7 @@ pub_eo_files = [
'efl_generic_model.eo', 'efl_generic_model.eo',
'efl_container_model.eo', 'efl_container_model.eo',
'efl_boolean_model.eo', 'efl_boolean_model.eo',
'efl_select_model.eo',
'efl_composite_model.eo', 'efl_composite_model.eo',
'efl_view_model.eo',
'efl_core_env.eo', 'efl_core_env.eo',
'efl_core_proc_env.eo', 'efl_core_proc_env.eo',
'efl_core_command_line.eo', 'efl_core_command_line.eo',
@ -141,11 +139,8 @@ ecore_src = [
'efl_container_model.c', 'efl_container_model.c',
'efl_composite_model.c', 'efl_composite_model.c',
'efl_boolean_model.c', 'efl_boolean_model.c',
'efl_select_model.c',
'efl_composite_model_private.h',
'efl_model_accessor_view.c', 'efl_model_accessor_view.c',
'efl_model_accessor_view_private.h', 'efl_model_accessor_view_private.h',
'efl_view_model.c',
'efl_filter_model.c', 'efl_filter_model.c',
'efl_linear_interpolator.c', 'efl_linear_interpolator.c',
'efl_accelerate_interpolator.c', 'efl_accelerate_interpolator.c',

View File

@ -276,6 +276,8 @@ typedef Eo Efl_Ui_Spotlight_Indicator;
# include <efl_ui_tab_bar.eo.h> # include <efl_ui_tab_bar.eo.h>
# include <efl_ui_tab_page.eo.h> # include <efl_ui_tab_page.eo.h>
# include <efl_ui_tab_pager.eo.h> # include <efl_ui_tab_pager.eo.h>
# include <efl_ui_select_model.eo.h>
# include <efl_ui_view_model.eo.h>
/** /**
* Initialize Elementary * Initialize Elementary
* *

View File

@ -2,20 +2,17 @@
# include <config.h> # include <config.h>
#endif #endif
#include "Eina.h" #include <Elementary.h>
#include "Efl.h" #include "elm_priv.h"
#include <Ecore.h>
#include "Eo.h"
#include "efl_select_model.eo.h" #include "efl_ui_select_model.eo.h"
#include "efl_model_accessor_view_private.h" #include "ecore_internal.h"
#include "efl_composite_model_private.h"
typedef struct _Efl_Select_Model_Data Efl_Select_Model_Data; typedef struct _Efl_Ui_Select_Model_Data Efl_Ui_Select_Model_Data;
struct _Efl_Select_Model_Data struct _Efl_Ui_Select_Model_Data
{ {
Efl_Select_Model_Data *parent; Efl_Ui_Select_Model_Data *parent;
unsigned long last; unsigned long last;
Eina_Bool single_selection : 1; Eina_Bool single_selection : 1;
@ -23,20 +20,20 @@ struct _Efl_Select_Model_Data
}; };
static Eo* static Eo*
_efl_select_model_efl_object_constructor(Eo *obj, _efl_ui_select_model_efl_object_constructor(Eo *obj,
Efl_Select_Model_Data *pd EINA_UNUSED) Efl_Ui_Select_Model_Data *pd EINA_UNUSED)
{ {
Eo *parent; Eo *parent;
obj = efl_constructor(efl_super(obj, EFL_SELECT_MODEL_CLASS)); obj = efl_constructor(efl_super(obj, EFL_UI_SELECT_MODEL_CLASS));
efl_boolean_model_boolean_add(obj, "selected", EINA_FALSE); efl_boolean_model_boolean_add(obj, "selected", EINA_FALSE);
pd->last = -1; pd->last = -1;
parent = efl_parent_get(obj); parent = efl_parent_get(obj);
if (efl_isa(parent, EFL_SELECT_MODEL_CLASS)) if (efl_isa(parent, EFL_UI_SELECT_MODEL_CLASS))
pd->parent = efl_data_scope_get(parent, EFL_SELECT_MODEL_CLASS); pd->parent = efl_data_scope_get(parent, EFL_UI_SELECT_MODEL_CLASS);
return obj; return obj;
} }
@ -44,7 +41,7 @@ _efl_select_model_efl_object_constructor(Eo *obj,
static Eina_Value static Eina_Value
_commit_change(Eo *child, void *data EINA_UNUSED, const Eina_Value v) _commit_change(Eo *child, void *data EINA_UNUSED, const Eina_Value v)
{ {
Efl_Select_Model_Data *pd; Efl_Ui_Select_Model_Data *pd;
Eina_Value *selected = NULL; Eina_Value *selected = NULL;
Eina_Bool selflag = EINA_FALSE; Eina_Bool selflag = EINA_FALSE;
@ -53,7 +50,7 @@ _commit_change(Eo *child, void *data EINA_UNUSED, const Eina_Value v)
selected = efl_model_property_get(child, "selected"); selected = efl_model_property_get(child, "selected");
pd = efl_data_scope_get(efl_parent_get(child), EFL_SELECT_MODEL_CLASS); pd = efl_data_scope_get(efl_parent_get(child), EFL_UI_SELECT_MODEL_CLASS);
if (!pd) goto on_error; if (!pd) goto on_error;
eina_value_bool_get(selected, &selflag); eina_value_bool_get(selected, &selflag);
@ -62,7 +59,7 @@ _commit_change(Eo *child, void *data EINA_UNUSED, const Eina_Value v)
// select case // select case
pd->none = EINA_FALSE; pd->none = EINA_FALSE;
pd->last = efl_composite_model_index_get(child); pd->last = efl_composite_model_index_get(child);
efl_event_callback_call(child, EFL_SELECT_MODEL_EVENT_SELECTED, child); efl_event_callback_call(child, EFL_UI_SELECT_MODEL_EVENT_SELECTED, child);
} }
else else
{ {
@ -75,7 +72,7 @@ _commit_change(Eo *child, void *data EINA_UNUSED, const Eina_Value v)
pd->last = 0; pd->last = 0;
pd->none = EINA_TRUE; pd->none = EINA_TRUE;
} }
efl_event_callback_call(child, EFL_SELECT_MODEL_EVENT_UNSELECTED, child); efl_event_callback_call(child, EFL_UI_SELECT_MODEL_EVENT_UNSELECTED, child);
} }
on_error: on_error:
@ -222,7 +219,7 @@ _untangle_error(void *data, Eina_Error err)
// where we could end up here. // where we could end up here.
Eina_Error *error = calloc(1, sizeof (Eina_Error)); Eina_Error *error = calloc(1, sizeof (Eina_Error));
f = efl_model_property_set(efl_super(child, EFL_SELECT_MODEL_CLASS), f = efl_model_property_set(efl_super(child, EFL_UI_SELECT_MODEL_CLASS),
"selected", eina_value_bool_new(EINA_FALSE)); "selected", eina_value_bool_new(EINA_FALSE));
// Once this is done, we need to repropagate the error // Once this is done, we need to repropagate the error
*error = err; *error = err;
@ -241,19 +238,19 @@ _untangle_free(void *data,
} }
static Eina_Iterator * static Eina_Iterator *
_efl_select_model_efl_model_properties_get(const Eo *obj, _efl_ui_select_model_efl_model_properties_get(const Eo *obj,
Efl_Select_Model_Data *pd EINA_UNUSED) Efl_Ui_Select_Model_Data *pd EINA_UNUSED)
{ {
EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(props, EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(props,
obj, EFL_SELECT_MODEL_CLASS, obj, EFL_UI_SELECT_MODEL_CLASS,
NULL, NULL,
"self.selected", "child.selected", "single_selection"); "self.selected", "child.selected", "single_selection");
return props; return props;
} }
static Eina_Future * static Eina_Future *
_efl_select_model_efl_model_property_set(Eo *obj, _efl_ui_select_model_efl_model_property_set(Eo *obj,
Efl_Select_Model_Data *pd, Efl_Ui_Select_Model_Data *pd,
const char *property, Eina_Value *value) const char *property, Eina_Value *value)
{ {
Eina_Value vf = EINA_VALUE_EMPTY; Eina_Value vf = EINA_VALUE_EMPTY;
@ -296,7 +293,7 @@ _efl_select_model_efl_model_property_set(Eo *obj,
Eina_Value *prev; Eina_Value *prev;
Eina_Future *chain; Eina_Future *chain;
prev = efl_model_property_get(efl_super(obj, EFL_SELECT_MODEL_CLASS), "selected"); prev = efl_model_property_get(efl_super(obj, EFL_UI_SELECT_MODEL_CLASS), "selected");
success = eina_value_bool_get(prev, &prevflag); success = eina_value_bool_get(prev, &prevflag);
success &= eina_value_bool_convert(value, &newflag); success &= eina_value_bool_convert(value, &newflag);
@ -309,7 +306,7 @@ _efl_select_model_efl_model_property_set(Eo *obj,
single_selection = pd->parent->single_selection; single_selection = pd->parent->single_selection;
// First store the new value in the boolean model we inherit from // First store the new value in the boolean model we inherit from
chain = efl_model_property_set(efl_super(obj, EFL_SELECT_MODEL_CLASS), chain = efl_model_property_set(efl_super(obj, EFL_UI_SELECT_MODEL_CLASS),
"selected", value); "selected", value);
// Now act ! // Now act !
@ -357,12 +354,12 @@ _efl_select_model_efl_model_property_set(Eo *obj,
.free = _clear_child); .free = _clear_child);
} }
return efl_model_property_set(efl_super(obj, EFL_SELECT_MODEL_CLASS), return efl_model_property_set(efl_super(obj, EFL_UI_SELECT_MODEL_CLASS),
property, value); property, value);
} }
static Eina_Value * static Eina_Value *
_efl_select_model_efl_model_property_get(const Eo *obj, Efl_Select_Model_Data *pd, const char *property) _efl_ui_select_model_efl_model_property_get(const Eo *obj, Efl_Ui_Select_Model_Data *pd, const char *property)
{ {
if (eina_streq("single_selection", property)) if (eina_streq("single_selection", property))
return eina_value_bool_new(pd->single_selection); return eina_value_bool_new(pd->single_selection);
@ -377,34 +374,34 @@ _efl_select_model_efl_model_property_get(const Eo *obj, Efl_Select_Model_Data *p
// Redirect to are we ourself selected // Redirect to are we ourself selected
if (pd->parent && eina_streq("self.selected", property)) if (pd->parent && eina_streq("self.selected", property))
{ {
return efl_model_property_get(efl_super(obj, EFL_SELECT_MODEL_CLASS), "selected"); return efl_model_property_get(efl_super(obj, EFL_UI_SELECT_MODEL_CLASS), "selected");
} }
return efl_model_property_get(efl_super(obj, EFL_SELECT_MODEL_CLASS), property); return efl_model_property_get(efl_super(obj, EFL_UI_SELECT_MODEL_CLASS), property);
} }
static void static void
_efl_select_model_single_selection_set(Eo *obj EINA_UNUSED, Efl_Select_Model_Data *pd, Eina_Bool enable) _efl_ui_select_model_single_selection_set(Eo *obj EINA_UNUSED, Efl_Ui_Select_Model_Data *pd, Eina_Bool enable)
{ {
pd->single_selection = enable; pd->single_selection = enable;
} }
static Eina_Bool static Eina_Bool
_efl_select_model_single_selection_get(const Eo *obj EINA_UNUSED, Efl_Select_Model_Data *pd) _efl_ui_select_model_single_selection_get(const Eo *obj EINA_UNUSED, Efl_Ui_Select_Model_Data *pd)
{ {
return pd->single_selection; return pd->single_selection;
} }
static Eina_Iterator * static Eina_Iterator *
_efl_select_model_selected_get(Eo *obj, Efl_Select_Model_Data *pd EINA_UNUSED) _efl_ui_select_model_selected_get(Eo *obj, Efl_Ui_Select_Model_Data *pd EINA_UNUSED)
{ {
return efl_boolean_model_boolean_iterator_get(obj, "selected", EINA_TRUE); return efl_boolean_model_boolean_iterator_get(obj, "selected", EINA_TRUE);
} }
static Eina_Iterator * static Eina_Iterator *
_efl_select_model_unselected_get(Eo *obj, Efl_Select_Model_Data *pd EINA_UNUSED) _efl_ui_select_model_unselected_get(Eo *obj, Efl_Ui_Select_Model_Data *pd EINA_UNUSED)
{ {
return efl_boolean_model_boolean_iterator_get(obj, "selected", EINA_FALSE); return efl_boolean_model_boolean_iterator_get(obj, "selected", EINA_FALSE);
} }
#include "efl_select_model.eo.c" #include "efl_ui_select_model.eo.c"

View File

@ -1,6 +1,6 @@
class @beta Efl.Select_Model extends Efl.Boolean_Model class @beta Efl.Ui.Select_Model extends Efl.Boolean_Model
{ {
[[Efl select model class]] [[Efl ui select model class]]
methods { methods {
selected_get { selected_get {
[[Get an iterator of all the selected child of this model. [[Get an iterator of all the selected child of this model.

View File

@ -2,31 +2,27 @@
# include <config.h> # include <config.h>
#endif #endif
#include <Efl.h> #include <Elementary.h>
#include <Eina.h> #include "elm_priv.h"
#include <Eo.h>
#include <Ecore.h>
#include "ecore_internal.h" #include "ecore_internal.h"
#include "efl_composite_model_private.h" typedef struct _Efl_Ui_View_Model_Data Efl_Ui_View_Model_Data;
typedef struct _Efl_Ui_View_Model_Bind Efl_Ui_View_Model_Bind;
typedef struct _Efl_Ui_View_Model_Text Efl_Ui_View_Model_Text;
typedef struct _Efl_Ui_View_Model_Logic Efl_Ui_View_Model_Logic;
typedef struct _Efl_Ui_View_Model_Property_Ref Efl_Ui_View_Model_Property_Ref;
typedef struct _Efl_View_Model_Data Efl_View_Model_Data; struct _Efl_Ui_View_Model_Data
typedef struct _Efl_View_Model_Bind Efl_View_Model_Bind;
typedef struct _Efl_View_Model_Text Efl_View_Model_Text;
typedef struct _Efl_View_Model_Logic Efl_View_Model_Logic;
typedef struct _Efl_View_Model_Property_Ref Efl_View_Model_Property_Ref;
struct _Efl_View_Model_Data
{ {
// FIXME: If parent is set, always access parent... recursively? // FIXME: If parent is set, always access parent... recursively?
Efl_View_Model_Data *parent; Efl_Ui_View_Model_Data *parent;
Eina_Hash *bound; // Stringhash of Efl_View_Model_Bind Eina_Hash *bound; // Stringhash of Efl_Ui_View_Model_Bind
Eina_Hash *logics; // Stringhash of Efl_View_Model_Logic Eina_Hash *logics; // Stringhash of Efl_Ui_View_Model_Logic
Eina_Hash *texts; // Stringhash of Efl_View_Model_Text Eina_Hash *texts; // Stringhash of Efl_Ui_View_Model_Text
Eina_Hash *deduplication; // Stringhash of Efl_View_Model_Property_Ref Eina_Hash *deduplication; // Stringhash of Efl_Ui_View_Model_Property_Ref
struct { struct {
Eina_Bool property_changed : 1; Eina_Bool property_changed : 1;
@ -37,7 +33,7 @@ struct _Efl_View_Model_Data
Eina_Bool children_bind : 1; // Define if child object should be automatically binded Eina_Bool children_bind : 1; // Define if child object should be automatically binded
}; };
struct _Efl_View_Model_Text struct _Efl_Ui_View_Model_Text
{ {
Eina_Stringshare *name; Eina_Stringshare *name;
Eina_Stringshare *definition; Eina_Stringshare *definition;
@ -46,21 +42,21 @@ struct _Efl_View_Model_Text
Efl_Model *self; Efl_Model *self;
}; };
struct _Efl_View_Model_Bind struct _Efl_Ui_View_Model_Bind
{ {
Eina_Stringshare *source; Eina_Stringshare *source;
Eina_List *destinations; Eina_List *destinations;
}; };
struct _Efl_View_Model_Logic struct _Efl_Ui_View_Model_Logic
{ {
struct { struct {
EflViewModelPropertyGet fct; EflUiViewModelPropertyGet fct;
Eina_Free_Cb free_cb; Eina_Free_Cb free_cb;
void *data; void *data;
} get; } get;
struct { struct {
EflViewModelPropertySet fct; EflUiViewModelPropertySet fct;
Eina_Free_Cb free_cb; Eina_Free_Cb free_cb;
void *data; void *data;
} set; } set;
@ -70,7 +66,7 @@ struct _Efl_View_Model_Logic
Eina_Stringshare *property; Eina_Stringshare *property;
}; };
struct _Efl_View_Model_Property_Ref struct _Efl_Ui_View_Model_Property_Ref
{ {
EINA_REFCOUNT; EINA_REFCOUNT;
Eina_Stringshare *property; Eina_Stringshare *property;
@ -79,21 +75,21 @@ struct _Efl_View_Model_Property_Ref
static void static void
_ref_free(void *data) _ref_free(void *data)
{ {
Efl_View_Model_Property_Ref *r = data; Efl_Ui_View_Model_Property_Ref *r = data;
eina_stringshare_del(r->property); eina_stringshare_del(r->property);
free(r); free(r);
} }
static void static void
_ref_add(Efl_View_Model_Data *pd, Eina_Stringshare *property) _ref_add(Efl_Ui_View_Model_Data *pd, Eina_Stringshare *property)
{ {
Efl_View_Model_Property_Ref *r; Efl_Ui_View_Model_Property_Ref *r;
r = eina_hash_find(pd->deduplication, property); r = eina_hash_find(pd->deduplication, property);
if (!r) if (!r)
{ {
r = calloc(1, sizeof (Efl_View_Model_Property_Ref)); r = calloc(1, sizeof (Efl_Ui_View_Model_Property_Ref));
if (!r) return ; if (!r) return ;
r->property = eina_stringshare_ref(property); r->property = eina_stringshare_ref(property);
@ -104,9 +100,9 @@ _ref_add(Efl_View_Model_Data *pd, Eina_Stringshare *property)
} }
static void static void
_ref_del(Efl_View_Model_Data *pd, Eina_Stringshare *property) _ref_del(Efl_Ui_View_Model_Data *pd, Eina_Stringshare *property)
{ {
Efl_View_Model_Property_Ref *r; Efl_Ui_View_Model_Property_Ref *r;
r = eina_hash_find(pd->deduplication, property); r = eina_hash_find(pd->deduplication, property);
if (!r) return ; if (!r) return ;
@ -118,14 +114,14 @@ _ref_del(Efl_View_Model_Data *pd, Eina_Stringshare *property)
static void static void
_logic_free(void *data) _logic_free(void *data)
{ {
Efl_View_Model_Logic *logic = data; Efl_Ui_View_Model_Logic *logic = data;
Eina_Stringshare *source; Eina_Stringshare *source;
if (logic->get.free_cb) logic->get.free_cb(logic->get.data); if (logic->get.free_cb) logic->get.free_cb(logic->get.data);
if (logic->set.free_cb) logic->set.free_cb(logic->set.data); if (logic->set.free_cb) logic->set.free_cb(logic->set.data);
EINA_LIST_FREE(logic->sources, source) EINA_LIST_FREE(logic->sources, source)
{ {
efl_view_model_property_unbind(logic->object, source, logic->property); efl_ui_view_model_property_unbind(logic->object, source, logic->property);
eina_stringshare_del(source); eina_stringshare_del(source);
} }
eina_stringshare_del(logic->property); eina_stringshare_del(logic->property);
@ -133,16 +129,16 @@ _logic_free(void *data)
} }
static Eina_Value * static Eina_Value *
_efl_view_model_property_dummy_get(void *data EINA_UNUSED, _efl_ui_view_model_property_dummy_get(void *data EINA_UNUSED,
const Efl_View_Model *view_model EINA_UNUSED, const Efl_Ui_View_Model *view_model EINA_UNUSED,
Eina_Stringshare *property EINA_UNUSED) Eina_Stringshare *property EINA_UNUSED)
{ {
return eina_value_error_new(EFL_MODEL_ERROR_NOT_SUPPORTED); return eina_value_error_new(EFL_MODEL_ERROR_NOT_SUPPORTED);
} }
static Eina_Future * static Eina_Future *
_efl_view_model_property_dummy_set(void *data EINA_UNUSED, _efl_ui_view_model_property_dummy_set(void *data EINA_UNUSED,
Efl_View_Model *view_model, Efl_Ui_View_Model *view_model,
Eina_Stringshare *property EINA_UNUSED, Eina_Stringshare *property EINA_UNUSED,
Eina_Value *value EINA_UNUSED) Eina_Value *value EINA_UNUSED)
{ {
@ -150,13 +146,13 @@ _efl_view_model_property_dummy_set(void *data EINA_UNUSED,
} }
static Eina_Error static Eina_Error
_efl_view_model_property_logic_add(Eo *obj, Efl_View_Model_Data *pd, _efl_ui_view_model_property_logic_add(Eo *obj, Efl_Ui_View_Model_Data *pd,
const char *property, const char *property,
void *get_data, EflViewModelPropertyGet get, Eina_Free_Cb get_free_cb, void *get_data, EflUiViewModelPropertyGet get, Eina_Free_Cb get_free_cb,
void *set_data, EflViewModelPropertySet set, Eina_Free_Cb set_free_cb, void *set_data, EflUiViewModelPropertySet set, Eina_Free_Cb set_free_cb,
Eina_Iterator *bound) Eina_Iterator *bound)
{ {
Efl_View_Model_Logic *logic; Efl_Ui_View_Model_Logic *logic;
Eina_Stringshare *prop; Eina_Stringshare *prop;
const char *source; const char *source;
@ -168,15 +164,15 @@ _efl_view_model_property_logic_add(Eo *obj, Efl_View_Model_Data *pd,
return EFL_MODEL_ERROR_INCORRECT_VALUE; return EFL_MODEL_ERROR_INCORRECT_VALUE;
} }
logic = calloc(1, sizeof (Efl_View_Model_Logic)); logic = calloc(1, sizeof (Efl_Ui_View_Model_Logic));
if (!logic) return ENOMEM; if (!logic) return ENOMEM;
logic->object = obj; logic->object = obj;
logic->property = prop; logic->property = prop;
logic->get.fct = get ? get : _efl_view_model_property_dummy_get; logic->get.fct = get ? get : _efl_ui_view_model_property_dummy_get;
logic->get.free_cb = get_free_cb; logic->get.free_cb = get_free_cb;
logic->get.data = get_data; logic->get.data = get_data;
logic->set.fct = set ? set : _efl_view_model_property_dummy_set; logic->set.fct = set ? set : _efl_ui_view_model_property_dummy_set;
logic->set.free_cb = set_free_cb; logic->set.free_cb = set_free_cb;
logic->set.data = set_data; logic->set.data = set_data;
@ -185,17 +181,17 @@ _efl_view_model_property_logic_add(Eo *obj, Efl_View_Model_Data *pd,
EINA_ITERATOR_FOREACH(bound, source) EINA_ITERATOR_FOREACH(bound, source)
{ {
logic->sources = eina_list_append(logic->sources, eina_stringshare_add(source)); logic->sources = eina_list_append(logic->sources, eina_stringshare_add(source));
efl_view_model_property_bind(obj, source, property); efl_ui_view_model_property_bind(obj, source, property);
} }
return 0; return 0;
} }
static Eina_Error static Eina_Error
_efl_view_model_property_logic_del(Eo *obj EINA_UNUSED, Efl_View_Model_Data *pd, _efl_ui_view_model_property_logic_del(Eo *obj EINA_UNUSED, Efl_Ui_View_Model_Data *pd,
const char *property) const char *property)
{ {
Efl_View_Model_Logic *logic; Efl_Ui_View_Model_Logic *logic;
logic = eina_hash_find(pd->logics, property); logic = eina_hash_find(pd->logics, property);
if (!logic) return EFL_MODEL_ERROR_INCORRECT_VALUE; if (!logic) return EFL_MODEL_ERROR_INCORRECT_VALUE;
@ -235,13 +231,13 @@ _lookup_next_token(const char *definition,
} }
static Eina_Error static Eina_Error
_efl_view_model_property_string_add(Eo *obj, Efl_View_Model_Data *pd, _efl_ui_view_model_property_string_add(Eo *obj, Efl_Ui_View_Model_Data *pd,
const char *name, const char *name,
const char *definition, const char *definition,
const char *not_ready, const char *not_ready,
const char *on_error) const char *on_error)
{ {
Efl_View_Model_Text *text; Efl_Ui_View_Model_Text *text;
Eina_Stringshare *sn; Eina_Stringshare *sn;
Eina_Slstr *st = NULL; Eina_Slstr *st = NULL;
Eina_Slstr *sp = NULL; Eina_Slstr *sp = NULL;
@ -255,9 +251,9 @@ _efl_view_model_property_string_add(Eo *obj, Efl_View_Model_Data *pd,
// Lookup if there is an existing property defined and undo it first // Lookup if there is an existing property defined and undo it first
text = eina_hash_find(pd->texts, sn); text = eina_hash_find(pd->texts, sn);
if (text) efl_view_model_property_string_del(obj, sn); if (text) efl_ui_view_model_property_string_del(obj, sn);
text = calloc(1, sizeof (Efl_View_Model_Text)); text = calloc(1, sizeof (Efl_Ui_View_Model_Text));
if (!text) goto on_error; if (!text) goto on_error;
err = EFL_MODEL_ERROR_INCORRECT_VALUE; err = EFL_MODEL_ERROR_INCORRECT_VALUE;
@ -272,21 +268,21 @@ _efl_view_model_property_string_add(Eo *obj, Efl_View_Model_Data *pd,
lookup; lookup;
definition += lookup, lookup = _lookup_next_token(definition, &st, &sp)) definition += lookup, lookup = _lookup_next_token(definition, &st, &sp))
{ {
if (sp) efl_view_model_property_bind(obj, sp, name); if (sp) efl_ui_view_model_property_bind(obj, sp, name);
} }
for (lookup = _lookup_next_token(not_ready, &st, &sp); for (lookup = _lookup_next_token(not_ready, &st, &sp);
lookup; lookup;
not_ready += lookup, lookup = _lookup_next_token(not_ready, &st, &sp)) not_ready += lookup, lookup = _lookup_next_token(not_ready, &st, &sp))
{ {
if (sp) efl_view_model_property_bind(obj, sp, name); if (sp) efl_ui_view_model_property_bind(obj, sp, name);
} }
for (lookup = _lookup_next_token(on_error, &st, &sp); for (lookup = _lookup_next_token(on_error, &st, &sp);
lookup; lookup;
on_error += lookup, lookup = _lookup_next_token(on_error, &st, &sp)) on_error += lookup, lookup = _lookup_next_token(on_error, &st, &sp))
{ {
if (sp) efl_view_model_property_bind(obj, sp, name); if (sp) efl_ui_view_model_property_bind(obj, sp, name);
} }
eina_hash_direct_add(pd->texts, text->name, text); eina_hash_direct_add(pd->texts, text->name, text);
@ -302,7 +298,7 @@ _efl_view_model_property_string_add(Eo *obj, Efl_View_Model_Data *pd,
static void static void
_text_free(void *data) _text_free(void *data)
{ {
Efl_View_Model_Text *text = data; Efl_Ui_View_Model_Text *text = data;
Eina_Stringshare *st; Eina_Stringshare *st;
Eina_Stringshare *sp; Eina_Stringshare *sp;
int lookup; int lookup;
@ -313,7 +309,7 @@ _text_free(void *data)
lookup; lookup;
tmp += lookup, lookup = _lookup_next_token(tmp, &st, &sp)) tmp += lookup, lookup = _lookup_next_token(tmp, &st, &sp))
{ {
if (sp) efl_view_model_property_unbind(text->self, sp, text->name); if (sp) efl_ui_view_model_property_unbind(text->self, sp, text->name);
} }
tmp = text->not_ready; tmp = text->not_ready;
@ -321,7 +317,7 @@ _text_free(void *data)
lookup; lookup;
tmp += lookup, lookup = _lookup_next_token(tmp, &st, &sp)) tmp += lookup, lookup = _lookup_next_token(tmp, &st, &sp))
{ {
if (sp) efl_view_model_property_unbind(text->self, sp, text->name); if (sp) efl_ui_view_model_property_unbind(text->self, sp, text->name);
} }
tmp = text->on_error; tmp = text->on_error;
@ -329,7 +325,7 @@ _text_free(void *data)
lookup; lookup;
tmp += lookup, lookup = _lookup_next_token(tmp, &st, &sp)) tmp += lookup, lookup = _lookup_next_token(tmp, &st, &sp))
{ {
if (sp) efl_view_model_property_unbind(text->self, sp, text->name); if (sp) efl_ui_view_model_property_unbind(text->self, sp, text->name);
} }
eina_stringshare_del(text->name); eina_stringshare_del(text->name);
@ -339,11 +335,11 @@ _text_free(void *data)
} }
static Eina_Error static Eina_Error
_efl_view_model_property_string_del(Eo *obj EINA_UNUSED, _efl_ui_view_model_property_string_del(Eo *obj EINA_UNUSED,
Efl_View_Model_Data *pd, Efl_Ui_View_Model_Data *pd,
const char *name) const char *name)
{ {
Efl_View_Model_Text *text; Efl_Ui_View_Model_Text *text;
Eina_Stringshare *sn; Eina_Stringshare *sn;
Eina_Error err = EFL_MODEL_ERROR_INCORRECT_VALUE; Eina_Error err = EFL_MODEL_ERROR_INCORRECT_VALUE;
@ -361,10 +357,10 @@ _efl_view_model_property_string_del(Eo *obj EINA_UNUSED,
} }
static void static void
_efl_view_model_property_bind(Eo *obj EINA_UNUSED, Efl_View_Model_Data *pd, _efl_ui_view_model_property_bind(Eo *obj EINA_UNUSED, Efl_Ui_View_Model_Data *pd,
const char *source, const char *destination) const char *source, const char *destination)
{ {
Efl_View_Model_Bind *bind; Efl_Ui_View_Model_Bind *bind;
Eina_Stringshare *src; Eina_Stringshare *src;
Eina_Stringshare *dst; Eina_Stringshare *dst;
@ -374,7 +370,7 @@ _efl_view_model_property_bind(Eo *obj EINA_UNUSED, Efl_View_Model_Data *pd,
bind = eina_hash_find(pd->bound, src); bind = eina_hash_find(pd->bound, src);
if (!bind) if (!bind)
{ {
bind = calloc(1, sizeof (Efl_View_Model_Bind)); bind = calloc(1, sizeof (Efl_Ui_View_Model_Bind));
if (!bind) goto on_error; if (!bind) goto on_error;
bind->source = eina_stringshare_ref(src); bind->source = eina_stringshare_ref(src);
@ -390,10 +386,10 @@ _efl_view_model_property_bind(Eo *obj EINA_UNUSED, Efl_View_Model_Data *pd,
} }
static void static void
_efl_view_model_property_unbind(Eo *obj EINA_UNUSED, Efl_View_Model_Data *pd, _efl_ui_view_model_property_unbind(Eo *obj EINA_UNUSED, Efl_Ui_View_Model_Data *pd,
const char *source, const char *destination) const char *source, const char *destination)
{ {
Efl_View_Model_Bind *bind; Efl_Ui_View_Model_Bind *bind;
Eina_Stringshare *src; Eina_Stringshare *src;
Eina_Stringshare *dst; Eina_Stringshare *dst;
Eina_Stringshare *cmp; Eina_Stringshare *cmp;
@ -426,7 +422,7 @@ _efl_view_model_property_unbind(Eo *obj EINA_UNUSED, Efl_View_Model_Data *pd,
static void static void
_bind_free(void *data) _bind_free(void *data)
{ {
Efl_View_Model_Bind *bind = data; Efl_Ui_View_Model_Bind *bind = data;
Eina_Stringshare *dst; Eina_Stringshare *dst;
eina_stringshare_del(bind->source); eina_stringshare_del(bind->source);
@ -438,11 +434,11 @@ _bind_free(void *data)
} }
static void static void
_efl_view_model_property_bind_lookup(Eina_Array *changed_properties, _efl_ui_view_model_property_bind_lookup(Eina_Array *changed_properties,
Efl_View_Model_Data *pd, Efl_Ui_View_Model_Data *pd,
Eina_Stringshare *src) Eina_Stringshare *src)
{ {
Efl_View_Model_Bind *bind; Efl_Ui_View_Model_Bind *bind;
if (!pd) return ; if (!pd) return ;
bind = eina_hash_find(pd->bound, src); bind = eina_hash_find(pd->bound, src);
@ -463,16 +459,16 @@ _efl_view_model_property_bind_lookup(Eina_Array *changed_properties,
if (dup == dest) continue ; if (dup == dest) continue ;
eina_array_push(changed_properties, dest); eina_array_push(changed_properties, dest);
_efl_view_model_property_bind_lookup(changed_properties, pd, dest); _efl_ui_view_model_property_bind_lookup(changed_properties, pd, dest);
} }
} }
_efl_view_model_property_bind_lookup(changed_properties, pd->parent, src); _efl_ui_view_model_property_bind_lookup(changed_properties, pd->parent, src);
} }
static void static void
_efl_view_model_property_changed(void *data, const Efl_Event *event) _efl_ui_view_model_property_changed(void *data, const Efl_Event *event)
{ {
Efl_View_Model_Data *pd = data; Efl_Ui_View_Model_Data *pd = data;
Efl_Model_Property_Event *ev = event->info; Efl_Model_Property_Event *ev = event->info;
Efl_Model_Property_Event nev = { 0 }; Efl_Model_Property_Event nev = { 0 };
const char *property; const char *property;
@ -493,7 +489,7 @@ _efl_view_model_property_changed(void *data, const Efl_Event *event)
eina_array_push(nev.changed_properties, property); eina_array_push(nev.changed_properties, property);
src = eina_stringshare_ref(property); src = eina_stringshare_ref(property);
_efl_view_model_property_bind_lookup(nev.changed_properties, pd, src); _efl_ui_view_model_property_bind_lookup(nev.changed_properties, pd, src);
} }
efl_event_callback_call(event->object, EFL_MODEL_EVENT_PROPERTIES_CHANGED, &nev); efl_event_callback_call(event->object, EFL_MODEL_EVENT_PROPERTIES_CHANGED, &nev);
@ -504,7 +500,7 @@ _efl_view_model_property_changed(void *data, const Efl_Event *event)
} }
static void static void
_efl_view_model_children_bind_set(Eo *obj EINA_UNUSED, Efl_View_Model_Data *pd, Eina_Bool enable) _efl_ui_view_model_children_bind_set(Eo *obj EINA_UNUSED, Efl_Ui_View_Model_Data *pd, Eina_Bool enable)
{ {
if (pd->finalized) return; if (pd->finalized) return;
@ -512,41 +508,41 @@ _efl_view_model_children_bind_set(Eo *obj EINA_UNUSED, Efl_View_Model_Data *pd,
} }
static Eina_Bool static Eina_Bool
_efl_view_model_children_bind_get(const Eo *obj EINA_UNUSED, Efl_View_Model_Data *pd) _efl_ui_view_model_children_bind_get(const Eo *obj EINA_UNUSED, Efl_Ui_View_Model_Data *pd)
{ {
return pd->children_bind; return pd->children_bind;
} }
static void static void
_efl_view_model_parent_data(Efl_View_Model *child, Efl_View_Model_Data *ppd) _efl_ui_view_model_parent_data(Efl_Ui_View_Model *child, Efl_Ui_View_Model_Data *ppd)
{ {
Efl_View_Model_Data *cpd; Efl_Ui_View_Model_Data *cpd;
cpd = efl_data_scope_get(child, EFL_VIEW_MODEL_CLASS); cpd = efl_data_scope_get(child, EFL_UI_VIEW_MODEL_CLASS);
cpd->parent = ppd; cpd->parent = ppd;
cpd->propagating = ppd->propagating; cpd->propagating = ppd->propagating;
} }
static Efl_View_Model * static Efl_Ui_View_Model *
_efl_view_model_child_lookup(Efl_View_Model_Data *pd, Efl_Object *parent, Efl_Model *view) _efl_ui_view_model_child_lookup(Efl_Ui_View_Model_Data *pd, Efl_Object *parent, Efl_Model *view)
{ {
EFL_COMPOSITE_LOOKUP_RETURN(co, parent, view, "_efl.view_model"); EFL_COMPOSITE_LOOKUP_RETURN(co, parent, view, "_efl.ui.view_model");
co = efl_add(EFL_VIEW_MODEL_CLASS, parent, co = efl_add(EFL_UI_VIEW_MODEL_CLASS, parent,
efl_ui_view_model_set(efl_added, view), efl_ui_view_model_set(efl_added, view),
_efl_view_model_parent_data(efl_added, pd)); _efl_ui_view_model_parent_data(efl_added, pd));
if (!co) return NULL; if (!co) return NULL;
EFL_COMPOSITE_REMEMBER_RETURN(co, view); EFL_COMPOSITE_REMEMBER_RETURN(co, view);
} }
static void static void
_efl_view_model_child_added(void *data, const Efl_Event *event) _efl_ui_view_model_child_added(void *data, const Efl_Event *event)
{ {
Efl_Model_Children_Event *ev = event->info; Efl_Model_Children_Event *ev = event->info;
Efl_Model_Children_Event nevt = { 0 }; Efl_Model_Children_Event nevt = { 0 };
Efl_View_Model_Data *pd = data; Efl_Ui_View_Model_Data *pd = data;
Efl_View_Model *co; Efl_Ui_View_Model *co;
if (pd->propagating.child_added) return ; if (pd->propagating.child_added) return ;
if (!pd->children_bind) return; if (!pd->children_bind) return;
@ -557,7 +553,7 @@ _efl_view_model_child_added(void *data, const Efl_Event *event)
// Our strategy is to rebuild a new Child_Add and cancel the current one. // Our strategy is to rebuild a new Child_Add and cancel the current one.
efl_event_callback_stop(event->object); efl_event_callback_stop(event->object);
co = _efl_view_model_child_lookup(pd, event->object, ev->child); co = _efl_ui_view_model_child_lookup(pd, event->object, ev->child);
if (!co) return; if (!co) return;
nevt.index = ev->index; nevt.index = ev->index;
@ -569,12 +565,12 @@ _efl_view_model_child_added(void *data, const Efl_Event *event)
} }
static void static void
_efl_view_model_child_removed(void *data, const Efl_Event *event) _efl_ui_view_model_child_removed(void *data, const Efl_Event *event)
{ {
Efl_Model_Children_Event *ev = event->info; Efl_Model_Children_Event *ev = event->info;
Efl_Model_Children_Event nevt = { 0 }; Efl_Model_Children_Event nevt = { 0 };
Efl_View_Model_Data *pd = data; Efl_Ui_View_Model_Data *pd = data;
Efl_View_Model *co; Efl_Ui_View_Model *co;
if (pd->propagating.child_removed) return ; if (pd->propagating.child_removed) return ;
if (!pd->children_bind) return; if (!pd->children_bind) return;
@ -585,7 +581,7 @@ _efl_view_model_child_removed(void *data, const Efl_Event *event)
// Our strategy is to rebuild a new Child_Add and cancel the current one. // Our strategy is to rebuild a new Child_Add and cancel the current one.
efl_event_callback_stop(event->object); efl_event_callback_stop(event->object);
co = _efl_view_model_child_lookup(pd, event->object, ev->child); co = _efl_ui_view_model_child_lookup(pd, event->object, ev->child);
if (!co) return; if (!co) return;
nevt.index = ev->index; nevt.index = ev->index;
@ -599,15 +595,15 @@ _efl_view_model_child_removed(void *data, const Efl_Event *event)
pd->propagating.child_removed = EINA_FALSE; pd->propagating.child_removed = EINA_FALSE;
} }
EFL_CALLBACKS_ARRAY_DEFINE(efl_view_model_intercept, EFL_CALLBACKS_ARRAY_DEFINE(efl_ui_view_model_intercept,
{ EFL_MODEL_EVENT_PROPERTIES_CHANGED, _efl_view_model_property_changed }, { EFL_MODEL_EVENT_PROPERTIES_CHANGED, _efl_ui_view_model_property_changed },
{ EFL_MODEL_EVENT_CHILD_ADDED, _efl_view_model_child_added }, { EFL_MODEL_EVENT_CHILD_ADDED, _efl_ui_view_model_child_added },
{ EFL_MODEL_EVENT_CHILD_REMOVED, _efl_view_model_child_removed }) { EFL_MODEL_EVENT_CHILD_REMOVED, _efl_ui_view_model_child_removed })
static Efl_Object * static Efl_Object *
_efl_view_model_efl_object_constructor(Eo *obj, Efl_View_Model_Data *pd) _efl_ui_view_model_efl_object_constructor(Eo *obj, Efl_Ui_View_Model_Data *pd)
{ {
obj = efl_constructor(efl_super(obj, EFL_VIEW_MODEL_CLASS)); obj = efl_constructor(efl_super(obj, EFL_UI_VIEW_MODEL_CLASS));
pd->children_bind = EINA_TRUE; pd->children_bind = EINA_TRUE;
pd->bound = eina_hash_stringshared_new(_bind_free); pd->bound = eina_hash_stringshared_new(_bind_free);
@ -615,23 +611,23 @@ _efl_view_model_efl_object_constructor(Eo *obj, Efl_View_Model_Data *pd)
pd->deduplication = eina_hash_stringshared_new(_ref_free); pd->deduplication = eina_hash_stringshared_new(_ref_free);
pd->texts = eina_hash_stringshared_new(_text_free); pd->texts = eina_hash_stringshared_new(_text_free);
efl_event_callback_array_priority_add(obj, efl_view_model_intercept(), EFL_CALLBACK_PRIORITY_BEFORE, pd); efl_event_callback_array_priority_add(obj, efl_ui_view_model_intercept(), EFL_CALLBACK_PRIORITY_BEFORE, pd);
return obj; return obj;
} }
static Efl_Object * static Efl_Object *
_efl_view_model_efl_object_finalize(Eo *obj, Efl_View_Model_Data *pd) _efl_ui_view_model_efl_object_finalize(Eo *obj, Efl_Ui_View_Model_Data *pd)
{ {
pd->finalized = EINA_TRUE; pd->finalized = EINA_TRUE;
return efl_finalize(efl_super(obj, EFL_VIEW_MODEL_CLASS)); return efl_finalize(efl_super(obj, EFL_UI_VIEW_MODEL_CLASS));
} }
static void static void
_efl_view_model_efl_object_destructor(Eo *obj, Efl_View_Model_Data *pd) _efl_ui_view_model_efl_object_destructor(Eo *obj, Efl_Ui_View_Model_Data *pd)
{ {
efl_event_callback_array_del(obj, efl_view_model_intercept(), pd); efl_event_callback_array_del(obj, efl_ui_view_model_intercept(), pd);
eina_hash_free(pd->bound); eina_hash_free(pd->bound);
pd->bound = NULL; pd->bound = NULL;
@ -645,30 +641,30 @@ _efl_view_model_efl_object_destructor(Eo *obj, Efl_View_Model_Data *pd)
eina_hash_free(pd->deduplication); eina_hash_free(pd->deduplication);
pd->deduplication = NULL; pd->deduplication = NULL;
efl_destructor(efl_super(obj, EFL_VIEW_MODEL_CLASS)); efl_destructor(efl_super(obj, EFL_UI_VIEW_MODEL_CLASS));
} }
static Efl_View_Model_Logic * static Efl_Ui_View_Model_Logic *
_efl_view_model_property_logic_lookup(Efl_View_Model_Data *pd, Eina_Stringshare *property) _efl_ui_view_model_property_logic_lookup(Efl_Ui_View_Model_Data *pd, Eina_Stringshare *property)
{ {
Efl_View_Model_Logic *logic; Efl_Ui_View_Model_Logic *logic;
if (!pd) return NULL; if (!pd) return NULL;
logic = eina_hash_find(pd->logics, property); logic = eina_hash_find(pd->logics, property);
if (!logic) return _efl_view_model_property_logic_lookup(pd->parent, property); if (!logic) return _efl_ui_view_model_property_logic_lookup(pd->parent, property);
return logic; return logic;
} }
static Eina_Future * static Eina_Future *
_efl_view_model_efl_model_property_set(Eo *obj, Efl_View_Model_Data *pd, _efl_ui_view_model_efl_model_property_set(Eo *obj, Efl_Ui_View_Model_Data *pd,
const char *property, Eina_Value *value) const char *property, Eina_Value *value)
{ {
Efl_View_Model_Logic *logic; Efl_Ui_View_Model_Logic *logic;
Eina_Stringshare *prop; Eina_Stringshare *prop;
Eina_Future *f; Eina_Future *f;
prop = eina_stringshare_add(property); prop = eina_stringshare_add(property);
logic = _efl_view_model_property_logic_lookup(pd, prop); logic = _efl_ui_view_model_property_logic_lookup(pd, prop);
if (logic) if (logic)
f = logic->set.fct(logic->get.data, obj, prop, value); f = logic->set.fct(logic->get.data, obj, prop, value);
else else
@ -676,7 +672,7 @@ _efl_view_model_efl_model_property_set(Eo *obj, Efl_View_Model_Data *pd,
if (eina_hash_find(pd->texts, prop)) if (eina_hash_find(pd->texts, prop))
f = efl_loop_future_rejected(obj, EFL_MODEL_ERROR_READ_ONLY); f = efl_loop_future_rejected(obj, EFL_MODEL_ERROR_READ_ONLY);
else else
f = efl_model_property_set(efl_super(obj, EFL_VIEW_MODEL_CLASS), property, value); f = efl_model_property_set(efl_super(obj, EFL_UI_VIEW_MODEL_CLASS), property, value);
} }
eina_stringshare_del(prop); eina_stringshare_del(prop);
@ -684,7 +680,7 @@ _efl_view_model_efl_model_property_set(Eo *obj, Efl_View_Model_Data *pd,
} }
static Eina_Value * static Eina_Value *
_efl_view_model_text_generate(const Eo *obj, _efl_ui_view_model_text_generate(const Eo *obj,
Eina_Strbuf *out, Eina_Strbuf *out,
Eina_Stringshare *pattern, Eina_Stringshare *pattern,
Eina_Bool stop_on_error) Eina_Bool stop_on_error)
@ -726,9 +722,9 @@ _efl_view_model_text_generate(const Eo *obj,
} }
static Eina_Value * static Eina_Value *
_efl_view_model_text_property_get(const Eo *obj, Efl_View_Model_Data *pd, Eina_Stringshare *prop) _efl_ui_view_model_text_property_get(const Eo *obj, Efl_Ui_View_Model_Data *pd, Eina_Stringshare *prop)
{ {
Efl_View_Model_Text *lookup; Efl_Ui_View_Model_Text *lookup;
Eina_Strbuf *buf; Eina_Strbuf *buf;
Eina_Value *r; Eina_Value *r;
Eina_Error err = 0; Eina_Error err = 0;
@ -737,11 +733,11 @@ _efl_view_model_text_property_get(const Eo *obj, Efl_View_Model_Data *pd, Eina_S
lookup = eina_hash_find(pd->texts, prop); lookup = eina_hash_find(pd->texts, prop);
// Lookup for property definition in the parent, but property value will be fetched on // Lookup for property definition in the parent, but property value will be fetched on
// the child object doing the request. // the child object doing the request.
if (!lookup) return _efl_view_model_text_property_get(obj, pd->parent, prop); if (!lookup) return _efl_ui_view_model_text_property_get(obj, pd->parent, prop);
buf = eina_strbuf_new(); buf = eina_strbuf_new();
r = _efl_view_model_text_generate(obj, buf, r = _efl_ui_view_model_text_generate(obj, buf,
lookup->definition, lookup->definition,
!!(lookup->on_error || lookup->not_ready)); !!(lookup->on_error || lookup->not_ready));
if (eina_value_type_get(r) != EINA_VALUE_TYPE_ERROR) if (eina_value_type_get(r) != EINA_VALUE_TYPE_ERROR)
@ -751,7 +747,7 @@ _efl_view_model_text_property_get(const Eo *obj, Efl_View_Model_Data *pd, Eina_S
eina_strbuf_reset(buf); eina_strbuf_reset(buf);
eina_value_free(r); eina_value_free(r);
r = _efl_view_model_text_generate(obj, buf, lookup->not_ready, !!lookup->on_error); r = _efl_ui_view_model_text_generate(obj, buf, lookup->not_ready, !!lookup->on_error);
if (eina_value_type_get(r) != EINA_VALUE_TYPE_ERROR) if (eina_value_type_get(r) != EINA_VALUE_TYPE_ERROR)
goto done; goto done;
} }
@ -760,7 +756,7 @@ _efl_view_model_text_property_get(const Eo *obj, Efl_View_Model_Data *pd, Eina_S
eina_strbuf_reset(buf); eina_strbuf_reset(buf);
eina_value_free(r); eina_value_free(r);
r = _efl_view_model_text_generate(obj, buf, lookup->on_error, 0); r = _efl_ui_view_model_text_generate(obj, buf, lookup->on_error, 0);
} }
done: done:
@ -770,21 +766,21 @@ _efl_view_model_text_property_get(const Eo *obj, Efl_View_Model_Data *pd, Eina_S
} }
static Eina_Value * static Eina_Value *
_efl_view_model_efl_model_property_get(const Eo *obj, Efl_View_Model_Data *pd, _efl_ui_view_model_efl_model_property_get(const Eo *obj, Efl_Ui_View_Model_Data *pd,
const char *property) const char *property)
{ {
Efl_View_Model_Logic *logic; Efl_Ui_View_Model_Logic *logic;
Eina_Stringshare *prop; Eina_Stringshare *prop;
Eina_Value *r; Eina_Value *r;
prop = eina_stringshare_add(property); prop = eina_stringshare_add(property);
logic = _efl_view_model_property_logic_lookup(pd, prop); logic = _efl_ui_view_model_property_logic_lookup(pd, prop);
if (logic) if (logic)
r = logic->get.fct(logic->get.data, obj, prop); r = logic->get.fct(logic->get.data, obj, prop);
else else
{ {
r = _efl_view_model_text_property_get(obj, pd, prop); r = _efl_ui_view_model_text_property_get(obj, pd, prop);
if (!r) r = efl_model_property_get(efl_super(obj, EFL_VIEW_MODEL_CLASS), property); if (!r) r = efl_model_property_get(efl_super(obj, EFL_UI_VIEW_MODEL_CLASS), property);
} }
eina_stringshare_del(prop); eina_stringshare_del(prop);
@ -792,25 +788,25 @@ _efl_view_model_efl_model_property_get(const Eo *obj, Efl_View_Model_Data *pd,
} }
static Eina_Iterator * static Eina_Iterator *
_efl_view_model_efl_model_properties_get(const Eo *obj, Efl_View_Model_Data *pd) _efl_ui_view_model_efl_model_properties_get(const Eo *obj, Efl_Ui_View_Model_Data *pd)
{ {
EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(props, obj, EFL_VIEW_MODEL_CLASS, EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(props, obj, EFL_UI_VIEW_MODEL_CLASS,
eina_hash_iterator_key_new(pd->deduplication)); eina_hash_iterator_key_new(pd->deduplication));
return props; return props;
} }
typedef struct _Efl_View_Model_Slice_Request Efl_View_Model_Slice_Request; typedef struct _Efl_Ui_View_Model_Slice_Request Efl_Ui_View_Model_Slice_Request;
struct _Efl_View_Model_Slice_Request struct _Efl_Ui_View_Model_Slice_Request
{ {
Efl_View_Model_Data *pd; Efl_Ui_View_Model_Data *pd;
unsigned int start; unsigned int start;
}; };
static Eina_Value static Eina_Value
_efl_view_model_slice_then(Eo *o, void *data, const Eina_Value v) _efl_ui_view_model_slice_then(Eo *o, void *data, const Eina_Value v)
{ {
Efl_View_Model_Slice_Request *req = data; Efl_Ui_View_Model_Slice_Request *req = data;
Eo *target; Eo *target;
Eina_Value r = EINA_VALUE_EMPTY; Eina_Value r = EINA_VALUE_EMPTY;
unsigned int i, len; unsigned int i, len;
@ -821,7 +817,7 @@ _efl_view_model_slice_then(Eo *o, void *data, const Eina_Value v)
{ {
Eo *composite; Eo *composite;
composite = _efl_view_model_child_lookup(req->pd, o, target); composite = _efl_ui_view_model_child_lookup(req->pd, o, target);
eina_value_array_append(&r, composite); eina_value_array_append(&r, composite);
} }
@ -829,21 +825,21 @@ _efl_view_model_slice_then(Eo *o, void *data, const Eina_Value v)
} }
static void static void
_efl_view_model_slice_clean(Eo *o EINA_UNUSED, void *data, const Eina_Future *dead_future EINA_UNUSED) _efl_ui_view_model_slice_clean(Eo *o EINA_UNUSED, void *data, const Eina_Future *dead_future EINA_UNUSED)
{ {
free(data); free(data);
} }
static Eina_Future * static Eina_Future *
_efl_view_model_efl_model_children_slice_get(Eo *obj, Efl_View_Model_Data *pd, _efl_ui_view_model_efl_model_children_slice_get(Eo *obj, Efl_Ui_View_Model_Data *pd,
unsigned int start, unsigned int count) unsigned int start, unsigned int count)
{ {
Efl_View_Model_Slice_Request *req; Efl_Ui_View_Model_Slice_Request *req;
Eina_Future *f; Eina_Future *f;
f = efl_model_children_slice_get(efl_super(obj, EFL_VIEW_MODEL_CLASS), start, count); f = efl_model_children_slice_get(efl_super(obj, EFL_UI_VIEW_MODEL_CLASS), start, count);
req = malloc(sizeof (Efl_View_Model_Slice_Request)); req = malloc(sizeof (Efl_Ui_View_Model_Slice_Request));
if (!req) if (!req)
{ {
eina_future_cancel(f); eina_future_cancel(f);
@ -854,9 +850,9 @@ _efl_view_model_efl_model_children_slice_get(Eo *obj, Efl_View_Model_Data *pd,
req->start = start; req->start = start;
return efl_future_then(obj, f, .success_type = EINA_VALUE_TYPE_ARRAY, return efl_future_then(obj, f, .success_type = EINA_VALUE_TYPE_ARRAY,
.success = _efl_view_model_slice_then, .success = _efl_ui_view_model_slice_then,
.free = _efl_view_model_slice_clean, .free = _efl_ui_view_model_slice_clean,
.data = req); .data = req);
} }
#include "efl_view_model.eo.c" #include "efl_ui_view_model.eo.c"

View File

@ -1,23 +1,23 @@
function @beta EflViewModelPropertyGet { function @beta EflUiViewModelPropertyGet {
[[Function called when a property is get.]] [[Function called when a property is get.]]
params { params {
@in view_model: const(Efl.View_Model); [[The ViewModel object the @.property.get is issued on.]] @in view_model: const(Efl.Ui.View_Model); [[The ViewModel object the @.property.get is issued on.]]
@in property: stringshare; [[The property name the @.property.get is issued on.]] @in property: stringshare; [[The property name the @.property.get is issued on.]]
} }
return: any_value_ptr; [[The property value.]] return: any_value_ptr; [[The property value.]]
}; };
function @beta EflViewModelPropertySet { function @beta EflUiViewModelPropertySet {
[[Function called when a property is set.]] [[Function called when a property is set.]]
params { params {
@in view_model: Efl.View_Model; [[The ViewModel object the @.property.set is issued on.]] @in view_model: Efl.Ui.View_Model; [[The ViewModel object the @.property.set is issued on.]]
@in property: stringshare; [[The property name the @.property.set is issued on.]] @in property: stringshare; [[The property name the @.property.set is issued on.]]
@in value: any_value_ptr @owned; [[The new value to set.]] @in value: any_value_ptr @owned; [[The new value to set.]]
} }
return: future<any_value_ptr>; [[The value that was finally set.]] return: future<any_value_ptr>; [[The value that was finally set.]]
}; };
class @beta Efl.View_Model extends Efl.Composite_Model class @beta Efl.Ui.View_Model extends Efl.Composite_Model
{ {
[[Efl model providing helpers for custom properties used when linking a model to a view and you need to [[Efl model providing helpers for custom properties used when linking a model to a view and you need to
generate/adapt values for display. generate/adapt values for display.
@ -70,9 +70,9 @@ class @beta Efl.View_Model extends Efl.Composite_Model
]] ]]
params { params {
property: string; [[The property to bind on to.]] property: string; [[The property to bind on to.]]
get: EflViewModelPropertyGet; [[Define the get callback called when the @Efl.Model.property.get is called get: EflUiViewModelPropertyGet; [[Define the get callback called when the @Efl.Model.property.get is called
with the above property name.]] with the above property name.]]
set: EflViewModelPropertySet; [[Define the set callback called when the @Efl.Model.property.set is called set: EflUiViewModelPropertySet; [[Define the set callback called when the @Efl.Model.property.set is called
with the above property name.]] with the above property name.]]
binded: iterator<string>; [[Iterator of property name to bind with this defined property see binded: iterator<string>; [[Iterator of property name to bind with this defined property see
@.property_bind.]] @.property_bind.]]
@ -100,7 +100,7 @@ class @beta Efl.View_Model extends Efl.Composite_Model
]] ]]
params { params {
@in source: string; [[Property name in the composited model.]] @in source: string; [[Property name in the composited model.]]
@in destination: string; [[Property name in the @Efl.View_Model]] @in destination: string; [[Property name in the @Efl.Ui.View_Model]]
} }
} }
property_unbind { property_unbind {
@ -110,7 +110,7 @@ class @beta Efl.View_Model extends Efl.Composite_Model
]] ]]
params { params {
@in source: string; [[Property name in the composited model.]] @in source: string; [[Property name in the composited model.]]
@in destination: string; [[Property name in the @Efl.View_Model]] @in destination: string; [[Property name in the @Efl.Ui.View_Model]]
} }
} }
@property children_bind { @property children_bind {
@ -139,6 +139,6 @@ class @beta Efl.View_Model extends Efl.Composite_Model
Efl.Model.property { set; get; } Efl.Model.property { set; get; }
} }
constructors { constructors {
Efl.View_Model.children_bind @optional; Efl.Ui.View_Model.children_bind @optional;
} }
} }

View File

@ -182,6 +182,8 @@ pub_eo_files = [
'efl_ui_single_selectable.eo', 'efl_ui_single_selectable.eo',
'efl_ui_position_manager_data_access_v1.eo', 'efl_ui_position_manager_data_access_v1.eo',
'efl_ui_tab_bar_default_item.eo', 'efl_ui_tab_bar_default_item.eo',
'efl_ui_select_model.eo',
'efl_ui_view_model.eo',
] ]
foreach eo_file : pub_eo_files foreach eo_file : pub_eo_files
@ -939,7 +941,9 @@ elementary_src = [
'efl_ui_position_manager_entity.c', 'efl_ui_position_manager_entity.c',
'efl_ui_position_manager_list.c', 'efl_ui_position_manager_list.c',
'efl_ui_position_manager_grid.c', 'efl_ui_position_manager_grid.c',
'efl_ui_tab_bar_default_item.c' 'efl_ui_tab_bar_default_item.c',
'efl_ui_select_model.c',
'efl_ui_view_model.c',
] ]
elementary_deps = [emile, eo, efl, edje, ethumb, ethumb_client, emotion, ecore_imf, ecore_con, eldbus, efreet, efreet_mime, efreet_trash, eio, atspi, dl, intl] elementary_deps = [emile, eo, efl, edje, ethumb, ethumb_client, emotion, ecore_imf, ecore_con, eldbus, efreet, efreet_mime, efreet_trash, eio, atspi, dl, intl]

View File

@ -27,7 +27,6 @@
static const Efl_Test_Case etc[] = { static const Efl_Test_Case etc[] = {
{ "Efl_Container_Model", efl_test_case_container_model }, { "Efl_Container_Model", efl_test_case_container_model },
{ "Efl_View_Model", efl_test_case_view_model },
{ "Efl_Boolean_Model", efl_test_case_boolean_model }, { "Efl_Boolean_Model", efl_test_case_boolean_model },
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -22,7 +22,6 @@
#include <check.h> #include <check.h>
#include "../efl_check.h" #include "../efl_check.h"
void efl_test_case_container_model(TCase *tc); void efl_test_case_container_model(TCase *tc);
void efl_test_case_view_model(TCase *tc);
void efl_test_case_boolean_model(TCase *tc); void efl_test_case_boolean_model(TCase *tc);
#endif /* EFL_SUITE_H_ */ #endif /* EFL_SUITE_H_ */

View File

@ -70,47 +70,6 @@ _children_slice_get_then(void *data EINA_UNUSED,
return v; return v;
} }
static Eina_Value
_selection_children_slice_get_then(void *data EINA_UNUSED,
const Eina_Value v,
const Eina_Future *dead_future EINA_UNUSED)
{
unsigned int i, len;
Efl_Model *child = NULL;
fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
{
Eina_Value *p_int = NULL;
Eina_Value *p_bool = NULL;
Eina_Value *p_index = NULL;
int v_int = 0;
unsigned int index = 0;
Eina_Bool v_bool = EINA_FALSE;
p_bool = efl_model_property_get(child, "selected");
p_int = efl_model_property_get(child, "test_p_int");
p_index = efl_model_property_get(child, "child.index");
eina_value_get(p_bool, &v_bool);
eina_value_get(p_int, &v_int);
fail_if(!eina_value_uint_convert(p_index, &index));
fail_if(v_bool != base_selections[i]);
fail_if(v_int != base_ints[i]);
ck_assert_int_eq(i, index);
eina_value_free(p_bool);
eina_value_free(p_int);
eina_value_free(p_index);
}
ecore_main_loop_quit();
return v;
}
EFL_START_TEST(efl_test_boolean_model) EFL_START_TEST(efl_test_boolean_model)
{ {
Efl_Generic_Model *base_model, *child; Efl_Generic_Model *base_model, *child;
@ -145,62 +104,6 @@ EFL_START_TEST(efl_test_boolean_model)
} }
EFL_END_TEST EFL_END_TEST
static Eina_Value
_wait_propagate(void *data EINA_UNUSED,
const Eina_Value v,
const Eina_Future *dead_future EINA_UNUSED)
{
ecore_main_loop_quit();
return v;
}
EFL_START_TEST(efl_test_select_model)
{
Efl_Generic_Model *base_model, *child;
int i;
Eina_Value v = { 0 };
Efl_Select_Model *model;
Eina_Future *future;
Eina_Iterator *it;
uint64_t *index;
eina_value_setup(&v, EINA_VALUE_TYPE_INT);
base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
ck_assert(!!base_model);
for (i = 0; i < child_number; ++i)
{
child = efl_model_child_add(base_model);
ck_assert(!!child);
ck_assert(eina_value_set(&v, base_ints[i]));
efl_model_property_set(child, "test_p_int", &v);
}
model = efl_add_ref(EFL_SELECT_MODEL_CLASS, efl_main_loop_get(),
efl_ui_view_model_set(efl_added, base_model));
ck_assert(!!model);
future = efl_model_property_set(model, "child.selected", eina_value_int_new(2));
eina_future_then(future, _wait_propagate, NULL, NULL);
ecore_main_loop_begin();
future = efl_model_children_slice_get(model, 0, efl_model_children_count_get(model));
eina_future_then(future, _selection_children_slice_get_then, NULL, NULL);
ecore_main_loop_begin();
it = efl_select_model_selected_get(model);
EINA_ITERATOR_FOREACH(it, index)
fail_if(*index != 2);
eina_iterator_free(it);
it = efl_select_model_unselected_get(model);
EINA_ITERATOR_FOREACH(it, index)
fail_if(*index == 2);
eina_iterator_free(it);
}
EFL_END_TEST
typedef struct _Efl_Filter_Model_Wait Efl_Filter_Model_Wait; typedef struct _Efl_Filter_Model_Wait Efl_Filter_Model_Wait;
struct _Efl_Filter_Model_Wait struct _Efl_Filter_Model_Wait
{ {
@ -465,6 +368,5 @@ void
efl_test_case_boolean_model(TCase *tc) efl_test_case_boolean_model(TCase *tc)
{ {
tcase_add_test(tc, efl_test_boolean_model); tcase_add_test(tc, efl_test_boolean_model);
tcase_add_test(tc, efl_test_select_model);
tcase_add_test(tc, efl_test_filter_model); tcase_add_test(tc, efl_test_filter_model);
} }

View File

@ -3,7 +3,6 @@ efl_suite_src = [
'efl_suite.h', 'efl_suite.h',
'efl_test_composite_model.c', 'efl_test_composite_model.c',
'efl_test_container_model.c', 'efl_test_container_model.c',
'efl_test_view_model.c'
] ]
efl_suite_bin = executable('efl_suite', efl_suite_bin = executable('efl_suite',

View File

@ -38,6 +38,8 @@ static const Efl_Test_Case etc[] = {
{ "efl_ui_collection", efl_ui_test_item_container }, { "efl_ui_collection", efl_ui_test_item_container },
{ "efl_ui_grid_container", efl_ui_test_grid_container }, { "efl_ui_grid_container", efl_ui_test_grid_container },
{ "efl_ui_list_container", efl_ui_test_list_container }, { "efl_ui_list_container", efl_ui_test_list_container },
{ "efl_ui_select_model", efl_ui_test_select_model },
{ "efl_ui_view_model", efl_ui_test_view_model },
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -49,6 +49,8 @@ void efl_ui_test_grid_container(TCase *tc);
void efl_ui_test_config(TCase *tc); void efl_ui_test_config(TCase *tc);
void efl_ui_test_popup(TCase *tc); void efl_ui_test_popup(TCase *tc);
void efl_ui_test_scroller(TCase *tc); void efl_ui_test_scroller(TCase *tc);
void efl_ui_test_select_model(TCase *tc);
void efl_ui_test_view_model(TCase *tc);
void loop_timer_interval_set(Eo *obj, double in); void loop_timer_interval_set(Eo *obj, double in);

View File

@ -0,0 +1,130 @@
/* EFL - EFL library
* Copyright (C) 2013 Cedric Bail
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library;
* if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "efl_ui_suite.h"
static const int child_number = 3;
static const int base_ints[] = { 41, 42, 43 };
static const Eina_Bool base_selections[] = { EINA_FALSE, EINA_FALSE, EINA_TRUE };
static Eina_Value
_selection_children_slice_get_then(void *data EINA_UNUSED,
const Eina_Value v,
const Eina_Future *dead_future EINA_UNUSED)
{
unsigned int i, len;
Efl_Model *child = NULL;
fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
{
Eina_Value *p_int = NULL;
Eina_Value *p_bool = NULL;
Eina_Value *p_index = NULL;
int v_int = 0;
unsigned int index = 0;
Eina_Bool v_bool = EINA_FALSE;
p_bool = efl_model_property_get(child, "selected");
p_int = efl_model_property_get(child, "test_p_int");
p_index = efl_model_property_get(child, "child.index");
eina_value_get(p_bool, &v_bool);
eina_value_get(p_int, &v_int);
fail_if(!eina_value_uint_convert(p_index, &index));
fail_if(v_bool != base_selections[i]);
fail_if(v_int != base_ints[i]);
ck_assert_int_eq(i, index);
eina_value_free(p_bool);
eina_value_free(p_int);
eina_value_free(p_index);
}
ecore_main_loop_quit();
return v;
}
static Eina_Value
_wait_propagate(void *data EINA_UNUSED,
const Eina_Value v,
const Eina_Future *dead_future EINA_UNUSED)
{
ecore_main_loop_quit();
return v;
}
EFL_START_TEST(efl_test_select_model)
{
Efl_Generic_Model *base_model, *child;
int i;
Eina_Value v = { 0 };
Efl_Ui_Select_Model *model;
Eina_Future *future;
Eina_Iterator *it;
uint64_t *index;
eina_value_setup(&v, EINA_VALUE_TYPE_INT);
base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
ck_assert(!!base_model);
for (i = 0; i < child_number; ++i)
{
child = efl_model_child_add(base_model);
ck_assert(!!child);
ck_assert(eina_value_set(&v, base_ints[i]));
efl_model_property_set(child, "test_p_int", &v);
}
model = efl_add_ref(EFL_UI_SELECT_MODEL_CLASS, efl_main_loop_get(),
efl_ui_view_model_set(efl_added, base_model));
ck_assert(!!model);
future = efl_model_property_set(model, "child.selected", eina_value_int_new(2));
eina_future_then(future, _wait_propagate, NULL, NULL);
ecore_main_loop_begin();
future = efl_model_children_slice_get(model, 0, efl_model_children_count_get(model));
eina_future_then(future, _selection_children_slice_get_then, NULL, NULL);
ecore_main_loop_begin();
it = efl_ui_select_model_selected_get(model);
EINA_ITERATOR_FOREACH(it, index)
fail_if(*index != 2);
eina_iterator_free(it);
it = efl_ui_select_model_unselected_get(model);
EINA_ITERATOR_FOREACH(it, index)
fail_if(*index == 2);
eina_iterator_free(it);
}
EFL_END_TEST
void
efl_ui_test_select_model(TCase *tc)
{
tcase_add_test(tc, efl_test_select_model);
}

View File

@ -20,10 +20,7 @@
# include "config.h" # include "config.h"
#endif #endif
#include "efl_suite.h" #include "efl_ui_suite.h"
#include <Efl.h>
#include <Ecore.h>
static const int child_number = 3; static const int child_number = 3;
static const int base_ints[] = { 41, 42, 43 }; static const int base_ints[] = { 41, 42, 43 };
@ -31,7 +28,7 @@ static const char *_efl_test_view_model_label_format = "Index %i.";
static const char *dependences[] = { "test_p_int" }; static const char *dependences[] = { "test_p_int" };
static Eina_Value * static Eina_Value *
_efl_test_view_model_label_get(void *data, const Efl_View_Model *mv, Eina_Stringshare *property) _efl_test_view_model_label_get(void *data, const Efl_Ui_View_Model *mv, Eina_Stringshare *property)
{ {
Eina_Strbuf *buf; Eina_Strbuf *buf;
Eina_Value *r; Eina_Value *r;
@ -54,7 +51,7 @@ _efl_test_view_model_label_get(void *data, const Efl_View_Model *mv, Eina_String
} }
static Eina_Future * static Eina_Future *
_efl_test_view_model_label_set(void *data EINA_UNUSED, Efl_View_Model *mv, Eina_Stringshare *property EINA_UNUSED, Eina_Value *value EINA_UNUSED) _efl_test_view_model_label_set(void *data EINA_UNUSED, Efl_Ui_View_Model *mv, Eina_Stringshare *property EINA_UNUSED, Eina_Value *value EINA_UNUSED)
{ {
return efl_loop_future_rejected(mv, EFL_MODEL_ERROR_READ_ONLY); return efl_loop_future_rejected(mv, EFL_MODEL_ERROR_READ_ONLY);
} }
@ -66,7 +63,7 @@ _efl_test_view_model_label_clean(void *data)
} }
static Eina_Value * static Eina_Value *
_efl_test_view_model_color_get(void *data EINA_UNUSED, const Efl_View_Model *mv, Eina_Stringshare *property) _efl_test_view_model_color_get(void *data EINA_UNUSED, const Efl_Ui_View_Model *mv, Eina_Stringshare *property)
{ {
Eina_Strbuf *buf; Eina_Strbuf *buf;
Eina_Value *r; Eina_Value *r;
@ -88,7 +85,7 @@ _efl_test_view_model_color_get(void *data EINA_UNUSED, const Efl_View_Model *mv,
} }
static Eina_Future * static Eina_Future *
_efl_test_view_model_color_set(void *data EINA_UNUSED, Efl_View_Model *mv, Eina_Stringshare *property EINA_UNUSED, Eina_Value *value EINA_UNUSED) _efl_test_view_model_color_set(void *data EINA_UNUSED, Efl_Ui_View_Model *mv, Eina_Stringshare *property EINA_UNUSED, Eina_Value *value EINA_UNUSED)
{ {
return efl_loop_future_rejected(mv, EFL_MODEL_ERROR_READ_ONLY); return efl_loop_future_rejected(mv, EFL_MODEL_ERROR_READ_ONLY);
} }
@ -318,36 +315,36 @@ EFL_START_TEST(efl_test_view_model)
efl_model_property_set(child, "test_p_int", &v); efl_model_property_set(child, "test_p_int", &v);
} }
mv = efl_add_ref(EFL_VIEW_MODEL_CLASS, efl_main_loop_get(), mv = efl_add_ref(EFL_UI_VIEW_MODEL_CLASS, efl_main_loop_get(),
efl_ui_view_model_set(efl_added, base_model)); efl_ui_view_model_set(efl_added, base_model));
ck_assert(!!mv); ck_assert(!!mv);
efl_view_model_property_logic_add(mv, "label", efl_ui_view_model_property_logic_add(mv, "label",
(void*) _efl_test_view_model_label_format, _efl_test_view_model_label_get, _efl_test_view_model_label_clean, (void*) _efl_test_view_model_label_format, _efl_test_view_model_label_get, _efl_test_view_model_label_clean,
(void*) _efl_test_view_model_label_format, _efl_test_view_model_label_set, _efl_test_view_model_label_clean, (void*) _efl_test_view_model_label_format, _efl_test_view_model_label_set, _efl_test_view_model_label_clean,
EINA_C_ARRAY_ITERATOR_NEW(dependences)); EINA_C_ARRAY_ITERATOR_NEW(dependences));
efl_view_model_property_logic_add(mv, "color", efl_ui_view_model_property_logic_add(mv, "color",
NULL, _efl_test_view_model_color_get, _efl_test_view_model_color_clean, NULL, _efl_test_view_model_color_get, _efl_test_view_model_color_clean,
NULL, _efl_test_view_model_color_set, _efl_test_view_model_color_clean, NULL, _efl_test_view_model_color_set, _efl_test_view_model_color_clean,
EINA_C_ARRAY_ITERATOR_NEW(dependences)); EINA_C_ARRAY_ITERATOR_NEW(dependences));
efl_view_model_property_logic_add(mv, "deadend", efl_ui_view_model_property_logic_add(mv, "deadend",
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL); NULL);
efl_view_model_property_string_add(mv, "output", efl_ui_view_model_property_string_add(mv, "output",
"${label} has ${color} for index ${index}", "${label} has ${color} for index ${index}",
"${index} not ready", "${index} not ready",
"${index} in error"); "${index} in error");
efl_view_model_property_string_add(mv, "broken", efl_ui_view_model_property_string_add(mv, "broken",
"${nope} has ${color} for index ${index}", "${nope} has ${color} for index ${index}",
"${index} not ready", "${index} not ready",
"${index} in error with '${nope}'"); "${index} in error with '${nope}'");
efl_view_model_property_string_add(mv, "weird", "${} % { } has ${", NULL, NULL); efl_ui_view_model_property_string_add(mv, "weird", "${} % { } has ${", NULL, NULL);
f = efl_model_children_slice_get(mv, 0, efl_model_children_count_get(mv)); f = efl_model_children_slice_get(mv, 0, efl_model_children_count_get(mv));
f = efl_future_then(mv, f, .success_type = EINA_VALUE_TYPE_ARRAY, f = efl_future_then(mv, f, .success_type = EINA_VALUE_TYPE_ARRAY,
@ -367,7 +364,7 @@ EFL_START_TEST(efl_test_view_model)
EFL_END_TEST EFL_END_TEST
void void
efl_test_case_view_model(TCase *tc) efl_ui_test_view_model(TCase *tc)
{ {
tcase_add_test(tc, efl_test_view_model); tcase_add_test(tc, efl_test_view_model);
} }

View File

@ -154,6 +154,8 @@ efl_ui_suite_src = [
'efl_ui_test_position_manager_common.c', 'efl_ui_test_position_manager_common.c',
'efl_ui_test_popup.c', 'efl_ui_test_popup.c',
'efl_ui_test_scroller.c', 'efl_ui_test_scroller.c',
'efl_ui_test_select_model.c',
'efl_ui_test_view_model.c',
] ]
efl_ui_suite = executable('efl_ui_suite', efl_ui_suite = executable('efl_ui_suite',