diff --git a/src/lib/efl/interfaces/efl_interfaces_main.c b/src/lib/efl/interfaces/efl_interfaces_main.c --- a/src/lib/efl/interfaces/efl_interfaces_main.c +++ b/src/lib/efl/interfaces/efl_interfaces_main.c @@ -118,15 +118,11 @@ static Eina_Value _efl_ui_view_factory_item_created(Eo *factory, void *data EINA_UNUSED, const Eina_Value v) { - Efl_Ui_Factory_Item_Created_Event event = { NULL, NULL }; + Efl_Gfx_Entity *item; int len, i; - EINA_VALUE_ARRAY_FOREACH(&v, len, i, event.item) - { - event.model = efl_ui_view_model_get(event.item); - - efl_event_callback_call(factory, EFL_UI_FACTORY_EVENT_CREATED, &event); - } + EINA_VALUE_ARRAY_FOREACH(&v, len, i, item) + efl_event_callback_call(factory, EFL_UI_FACTORY_EVENT_ITEM_CREATED, item); return v; } diff --git a/src/lib/efl/interfaces/efl_ui_factory.eo b/src/lib/efl/interfaces/efl_ui_factory.eo --- a/src/lib/efl/interfaces/efl_ui_factory.eo +++ b/src/lib/efl/interfaces/efl_ui_factory.eo @@ -11,6 +11,8 @@ This object represents a Factory in the factory pattern. Objects should be created via the method @Efl.Ui.View_Factory.create_with_event, which will in turn call the necessary APIs from this interface. Objects created this way should be removed using @.release. + + It is recommended to not create your own @Efl.Ui.Factory and use event handler as much as possible. ]] methods { create @protected { @@ -31,18 +33,12 @@ ui_view: Efl.Gfx.Entity; [[Object to remove.]] } } - building @const { - [[This function is called during the creation of an UI object between the @Efl.Object.constructor and - @Efl.Object.finalize call. - - Note: If the @Efl.Ui.Factory does keep a cache of objects, this won't be called when objects are pulled out - of the cache.]] - params { - ui_view: Efl.Gfx.Entity; [[The UI object being created.]] - } - } } events { - created: Efl.Ui.Factory_Item_Created_Event; [[Event triggered when an item has been successfully created.]] + item,constructing: Efl.Gfx.Entity; [[Event triggered when an item is under construction (between the @Efl.Object.constructor and @Efl.Object.finalize call on the item). + Note: If the @Efl.Ui.Factory does keep a cache of objects, this won't be called when objects are pulled out of the cache.]] + item,building: Efl.Gfx.Entity; [[Event triggered when an item has processed @Efl.Object.finalize, but before all the factory are done building it. + Note: if the @Efl.Ui.Factory does keep a cache of object, this will be called when object are pulled out of the cache.]] + item,created: Efl.Gfx.Entity; [[Event triggered when an item has been successfully created by the factory and is about to be used by an @Efl.Ui.View.]] } } diff --git a/src/lib/elementary/efl_ui_caching_factory.c b/src/lib/elementary/efl_ui_caching_factory.c --- a/src/lib/elementary/efl_ui_caching_factory.c +++ b/src/lib/elementary/efl_ui_caching_factory.c @@ -246,8 +246,9 @@ EINA_ITERATOR_FOREACH(models, model) { w = efl_add(pd->klass, parent, - efl_ui_factory_building(obj, efl_added), - efl_ui_view_model_set(efl_added, model)); + efl_ui_view_model_set(efl_added, model), + efl_event_callback_call(obj, EFL_UI_FACTORY_EVENT_ITEM_CONSTRUCTING, efl_added)); + efl_event_callback_call(obj, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, w); eina_value_array_append(&gr->done, w); } diff --git a/src/lib/elementary/efl_ui_image_factory.c b/src/lib/elementary/efl_ui_image_factory.c --- a/src/lib/elementary/efl_ui_image_factory.c +++ b/src/lib/elementary/efl_ui_image_factory.c @@ -15,12 +15,23 @@ Eina_Stringshare *property; } Efl_Ui_Image_Factory_Data; +static void +_efl_ui_image_factory_building(void *data, const Efl_Event *ev) +{ + Efl_Ui_Image_Factory_Data *pd = data; + Efl_Gfx_Entity *ui_view = ev->info; + + efl_ui_property_bind(ui_view, "filename", pd->property); +} + EOLIAN static Eo * _efl_ui_image_factory_efl_object_constructor(Eo *obj, Efl_Ui_Image_Factory_Data *pd) { obj = efl_constructor(efl_super(obj, MY_CLASS)); efl_ui_widget_factory_item_class_set(obj, EFL_UI_IMAGE_CLASS); + efl_event_callback_add(obj, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, _efl_ui_image_factory_building, pd); + pd->property = NULL; return obj; @@ -35,14 +46,6 @@ efl_destructor(efl_super(obj, MY_CLASS)); } -EOLIAN static void -_efl_ui_image_factory_efl_ui_factory_building(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Factory_Data *pd, Efl_Gfx_Entity *ui_view) -{ - efl_ui_property_bind(ui_view, "filename", pd->property); - - efl_ui_factory_building(efl_super(obj, EFL_UI_IMAGE_FACTORY_CLASS), ui_view); -} - EOLIAN static Eina_Future * _efl_ui_image_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Image_Factory_Data *pd, Eina_Iterator *models, Efl_Gfx_Entity *parent) diff --git a/src/lib/elementary/efl_ui_image_factory.eo b/src/lib/elementary/efl_ui_image_factory.eo --- a/src/lib/elementary/efl_ui_image_factory.eo +++ b/src/lib/elementary/efl_ui_image_factory.eo @@ -5,7 +5,6 @@ Efl.Object.constructor; Efl.Object.destructor; Efl.Ui.Factory.create; - Efl.Ui.Factory.building; Efl.Ui.Property_Bind.property_bind; } } diff --git a/src/lib/elementary/efl_ui_layout_factory.c b/src/lib/elementary/efl_ui_layout_factory.c --- a/src/lib/elementary/efl_ui_layout_factory.c +++ b/src/lib/elementary/efl_ui_layout_factory.c @@ -44,6 +44,22 @@ return EINA_TRUE; } +static void +_efl_ui_layout_factory_building(void *data, const Efl_Event *event) +{ + Efl_Ui_Layout_Factory_Data *pd = data; + Efl_Gfx_Entity *ui_view = event->info; + + if (pd->klass || pd->group || pd->style) + efl_ui_layout_theme_set(ui_view, pd->klass, pd->group, pd->style); + + eina_hash_foreach(pd->bind.properties, _property_bind, ui_view); + eina_hash_foreach(pd->bind.factories, _factory_bind, ui_view); + + efl_gfx_hint_weight_set(ui_view, EFL_GFX_HINT_EXPAND, 0); + efl_gfx_hint_fill_set(ui_view, EINA_TRUE, EINA_TRUE); +} + EOLIAN static Eo * _efl_ui_layout_factory_efl_object_constructor(Eo *obj, Efl_Ui_Layout_Factory_Data *pd) { @@ -54,6 +70,8 @@ pd->bind.properties = eina_hash_stringshared_new(EINA_FREE_CB(eina_stringshare_del)); pd->bind.factories = eina_hash_stringshared_new(EINA_FREE_CB(efl_unref)); + efl_event_callback_add(obj, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, _efl_ui_layout_factory_building, pd); + return obj; } @@ -70,21 +88,6 @@ efl_destructor(efl_super(obj, MY_CLASS)); } -static void -_efl_ui_layout_factory_efl_ui_factory_building(const Eo *obj, Efl_Ui_Layout_Factory_Data *pd, Efl_Gfx_Entity *ui_view) -{ - if (pd->klass || pd->group || pd->style) - efl_ui_layout_theme_set(ui_view, pd->klass, pd->group, pd->style); - - eina_hash_foreach(pd->bind.properties, _property_bind, ui_view); - eina_hash_foreach(pd->bind.factories, _factory_bind, ui_view); - - efl_gfx_hint_weight_set(ui_view, EFL_GFX_HINT_EXPAND, 0); - efl_gfx_hint_fill_set(ui_view, EINA_TRUE, EINA_TRUE); - - efl_ui_factory_building(efl_super(obj, EFL_UI_LAYOUT_FACTORY_CLASS), ui_view); -} - EOLIAN static void _efl_ui_layout_factory_efl_ui_factory_bind_factory_bind(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Factory_Data *pd, const char *key, Efl_Ui_Factory *factory) diff --git a/src/lib/elementary/efl_ui_layout_factory.eo b/src/lib/elementary/efl_ui_layout_factory.eo --- a/src/lib/elementary/efl_ui_layout_factory.eo +++ b/src/lib/elementary/efl_ui_layout_factory.eo @@ -15,7 +15,6 @@ implements { Efl.Object.constructor; Efl.Object.destructor; - Efl.Ui.Factory.building; Efl.Ui.Property_Bind.property_bind; Efl.Ui.Factory_Bind.factory_bind; } diff --git a/src/lib/elementary/efl_ui_widget_factory.c b/src/lib/elementary/efl_ui_widget_factory.c --- a/src/lib/elementary/efl_ui_widget_factory.c +++ b/src/lib/elementary/efl_ui_widget_factory.c @@ -69,8 +69,20 @@ } static void -_efl_ui_widget_factory_efl_ui_factory_building(const Eo *factory EINA_UNUSED, Efl_Ui_Widget_Factory_Data *pd, Efl_Gfx_Entity *ui_view) +_efl_ui_widget_factory_constructing(void *data EINA_UNUSED, const Efl_Event *ev) { + Efl_Gfx_Entity *ui_view = ev->info; + + /* NOP */ + (void)(ui_view); +} + + +static void +_efl_ui_widget_factory_building(void *data, const Efl_Event *ev) +{ + Efl_Gfx_Entity *ui_view = ev->info; + Efl_Ui_Widget_Factory_Data *pd = data; const Efl_Model *model; Eina_Value *property, *width, *height; Efl_Ui_Bind_Part_Data *bpd; @@ -122,6 +134,21 @@ eina_value_free(property); } +EFL_CALLBACKS_ARRAY_DEFINE(item_callbacks, + { EFL_UI_FACTORY_EVENT_ITEM_CONSTRUCTING, _efl_ui_widget_factory_constructing }, + { EFL_UI_FACTORY_EVENT_ITEM_BUILDING, _efl_ui_widget_factory_building }) + +static Eo * +_efl_ui_widget_factory_efl_object_constructor(Efl_Ui_Widget_Factory *obj, + Efl_Ui_Widget_Factory_Data *pd) +{ + obj = efl_constructor(efl_super(obj, EFL_UI_WIDGET_FACTORY_CLASS)); + + efl_event_callback_array_add(obj, item_callbacks(), pd); + + return obj; +} + static Efl_Ui_Widget * _efl_ui_widget_create(const Efl_Ui_Factory *factory, const Efl_Class *klass, Eo *parent, @@ -131,7 +158,8 @@ w = efl_add(klass, parent, efl_ui_view_model_set(efl_added, model), - efl_ui_factory_building(factory, efl_added)); + efl_event_callback_call((Efl_Ui_Factory *) factory, EFL_UI_FACTORY_EVENT_ITEM_CONSTRUCTING, efl_added)); + efl_event_callback_call((Efl_Ui_Factory *) factory, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, w); return w; } diff --git a/src/lib/elementary/efl_ui_widget_factory.eo b/src/lib/elementary/efl_ui_widget_factory.eo --- a/src/lib/elementary/efl_ui_widget_factory.eo +++ b/src/lib/elementary/efl_ui_widget_factory.eo @@ -4,7 +4,6 @@ This factory is designed to build @Efl.Ui.Widget and optionally set their @Efl.Ui.Widget.style if it was connected with @Efl.Ui.Property_Bind.property_bind "$style". - ]] methods { @property item_class { @@ -18,9 +17,9 @@ } implements { + Efl.Object.constructor; Efl.Ui.Factory.create; Efl.Ui.Factory.release; - Efl.Ui.Factory.building; Efl.Ui.Property_Bind.property_bind; Efl.Part.part_get; }