[elm] New infra to help factorize initting code for

widgets.

Some of them have initting code using the parent ptr for some logic.
Now there's a new idiom on instantiating widgets which adresses
that. It'll be used for all widgets from now on.



SVN revision: 74147
This commit is contained in:
Gustavo Lima Chaves 2012-07-18 21:03:28 +00:00
parent 844889a9f7
commit 5a44c924e4
2 changed files with 37 additions and 5 deletions

View File

@ -922,6 +922,33 @@ elm_widget_smart_class_get(void)
return class;
}
EAPI Evas_Object *
elm_widget_add(Evas_Smart *smart,
Evas_Object *parent)
{
Evas *e;
Evas_Object *o;
e = evas_object_evas_get(parent);
if (!e) return NULL;
o = evas_object_smart_add(e, smart);
elm_widget_parent_set(o, parent);
return o;
}
EAPI void
elm_widget_parent_set(Evas_Object *obj,
Evas_Object *parent)
{
ELM_WIDGET_DATA_GET(obj, sd);
if (!sd->api->parent_set) return;
sd->api->parent_set(obj, parent);
}
EAPI void
elm_widget_type_register(const char **ptr)
{
@ -1018,7 +1045,7 @@ _elm_widget_compat_smart_set_user(Elm_Widget_Compat_Smart_Class *sc)
}
EAPI Evas_Object *
elm_widget_add(Evas *evas)
elm_widget_compat_add(Evas *evas)
{
return evas_object_smart_add(evas, _elm_widget_compat_smart_class_new());
}

View File

@ -356,7 +356,7 @@
*/
#define ELM_WIDGET_SMART_CLASS_INIT(smart_class_init) \
{smart_class_init, ELM_WIDGET_SMART_CLASS_VERSION, NULL, NULL, NULL, NULL, \
NULL, NULL, NULL, NULL, NULL, NULL}
NULL, NULL, NULL, NULL, NULL, NULL, NULL}
/**
* @def ELM_WIDGET_SMART_CLASS_INIT_NULL
@ -406,6 +406,8 @@ typedef struct _Elm_Widget_Smart_Class
Evas_Smart_Class base; /**< Base smart class struct, needed for all smart objects */
int version; /**< Version of this smart class definition */
void (*parent_set)(Evas_Object *obj,
Evas_Object *parent); /**< 'Virtual' function handling parent widget attachment to new object */
Eina_Bool (*on_focus)(Evas_Object *obj); /**< 'Virtual' function handling receipt of focus on the widget */
Eina_Bool (*disable)(Evas_Object *obj); /**< 'Virtual' function on the widget being disabled */
Eina_Bool (*theme)(Evas_Object *obj); /**< 'Virtual' function on the widget being re-themed */
@ -428,7 +430,8 @@ typedef struct _Elm_Widget_Smart_Class
Eina_Bool (*sub_object_del)(Evas_Object *obj,
Evas_Object *sobj); /**< 'Virtual' function handling sub objects being removed */
void (*access)(Evas_Object *obj, Eina_Bool is_access); /**< 'Virtual' function on the widget being set access */
void (*access)(Evas_Object *obj,
Eina_Bool is_access); /**< 'Virtual' function on the widget being set access */
} Elm_Widget_Smart_Class;
/**
@ -613,8 +616,10 @@ struct _Elm_Object_Item
#define ELM_NEW(t) calloc(1, sizeof(t))
EAPI Evas_Object *elm_widget_add(Evas_Smart *, Evas_Object *);
EAPI void elm_widget_parent_set(Evas_Object *, Evas_Object *);
EAPI Eina_Bool elm_widget_api_check(int ver);
EAPI Evas_Object *elm_widget_add(Evas *evas);
EAPI Evas_Object *elm_widget_compat_add(Evas *evas);
EAPI void elm_widget_del_hook_set(Evas_Object *obj, void (*func)(Evas_Object *obj));
EAPI void elm_widget_del_pre_hook_set(Evas_Object *obj, void (*func)(Evas_Object *obj));
EAPI void elm_widget_focus_hook_set(Evas_Object *obj, void (*func)(Evas_Object *obj));
@ -1059,7 +1064,7 @@ EAPI void elm_widget_tree_dot_dump(const Evas_Object *top, FILE *out
EINA_SAFETY_ON_NULL_RETURN_VAL((par), (ret)); \
evas = evas_object_evas_get(par); if (!(evas)) return (ret); \
wdat = ELM_NEW(wdtype); if (!(wdat)) return (ret); \
ob = elm_widget_add(evas); if (!(ob)) { free(wdat); return (ret); } \
ob = elm_widget_compat_add(evas); if (!(ob)) { free(wdat); return (ret); } \
} while (0)
#define ELM_OBJ_ITEM_CHECK_OR_RETURN(it, ...) \