Eobj: added default constructor/destructor.
[profile/ivi/eobj.git] / examples / evas / elw_box.c
1 #include <Elementary.h>
2
3 #include "Eobj.h"
4 #include "evas_obj.h"
5 #include "elw_box.h"
6
7 EAPI Eobj_Op ELW_BOX_BASE_ID = 0;
8
9 typedef struct
10 {
11    Evas_Object *bx;
12 } Widget_Data;
13
14 static Eobj_Class *_my_class = NULL;
15
16 static void
17 _pack_end(Eobj *obj, Eobj_Op op, va_list *list)
18 {
19    Widget_Data *wd = eobj_data_get(obj, _my_class);
20    (void) op;
21    Eobj *child_obj;
22    child_obj = va_arg(*list, Eobj *);
23    /* FIXME: Ref and the later uref child_obj here... */
24    elm_box_pack_end(wd->bx, eobj_evas_object_get(child_obj));
25 }
26
27 static void
28 _constructor(Eobj *obj)
29 {
30    eobj_constructor_super(obj);
31
32    Widget_Data *wd = eobj_data_get(obj, _my_class);
33
34    /* FIXME: An hack, because our tree is not yet only Eobj */
35    wd->bx = elm_box_add(eobj_evas_object_get(eobj_parent_get(obj)));
36    evas_object_size_hint_align_set(wd->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
37    evas_object_size_hint_weight_set(wd->bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
38
39    eobj_evas_object_set(obj, wd->bx);
40 }
41
42 static void
43 _class_constructor(Eobj_Class *klass)
44 {
45    const Eobj_Op_Func_Description func_desc[] = {
46         EOBJ_OP_FUNC_DESCRIPTION(ELW_BOX_ID(ELW_BOX_SUB_ID_PACK_END), _pack_end),
47         EOBJ_OP_FUNC_DESCRIPTION_SENTINEL
48    };
49
50    eobj_class_funcs_set(klass, func_desc);
51 }
52
53 const Eobj_Class *
54 elw_box_class_get(void)
55 {
56    if (_my_class) return _my_class;
57
58    static const Eobj_Op_Description op_desc[] = {
59         EOBJ_OP_DESCRIPTION(ELW_BOX_SUB_ID_PACK_END, "o", "Pack obj at the end of box."),
60         EOBJ_OP_DESCRIPTION_SENTINEL
61    };
62
63    static const Eobj_Class_Description class_desc = {
64         "Elw Box",
65         EOBJ_CLASS_TYPE_REGULAR,
66         EOBJ_CLASS_DESCRIPTION_OPS(&ELW_BOX_BASE_ID, op_desc, ELW_BOX_SUB_ID_LAST),
67         NULL,
68         sizeof(Widget_Data),
69         _constructor,
70         NULL,
71         _class_constructor,
72         NULL
73    };
74
75    return _my_class = eobj_class_new(&class_desc, EVAS_OBJ_CLASS, NULL);
76 }
77