aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/elementary/efl_ui_layout_factory.c
blob: 15246ffa713d09e410d685a4a3a20a868eae9a4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include <Elementary.h>
#include "elm_priv.h"

#define MY_CLASS EFL_UI_LAYOUT_FACTORY_CLASS
#define MY_CLASS_NAME "Efl.Ui.Layout_Factory"

typedef struct _Efl_Ui_Layout_Factory_Data
{
    struct {
       Eina_Hash *properties;
       Eina_Hash *factories;
    } bind;
    Eina_Stringshare *klass;
    Eina_Stringshare *group;
    Eina_Stringshare *style;
} Efl_Ui_Layout_Factory_Data;

Eina_Bool
_property_bind(const Eina_Hash *hash EINA_UNUSED, const void *key, void *data, void *fdata)
{
   Eo *layout = fdata;
   Eina_Stringshare *ss_key = key;
   Eina_Stringshare *property = data;

   efl_ui_property_bind(layout, ss_key, property);

   return EINA_TRUE;
}

Eina_Bool
_factory_bind(const Eina_Hash *hash EINA_UNUSED, const void *key, void *data, void *fdata)
{
   Eo *layout = fdata;
   Eina_Stringshare *ss_key = key;
   Efl_Ui_Factory *factory = data;

   efl_ui_factory_bind(layout, ss_key, factory);
   return EINA_TRUE;
}

EOLIAN static Eo *
_efl_ui_layout_factory_efl_object_constructor(Eo *obj, Efl_Ui_Layout_Factory_Data *pd)
{
   obj = efl_constructor(efl_super(obj, MY_CLASS));

   efl_ui_widget_factory_item_class_set(obj, EFL_UI_LAYOUT_CLASS);

   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));

   return obj;
}

EOLIAN static void
_efl_ui_layout_factory_efl_object_destructor(Eo *obj, Efl_Ui_Layout_Factory_Data *pd)
{
   eina_stringshare_del(pd->klass);
   eina_stringshare_del(pd->group);
   eina_stringshare_del(pd->style);

   eina_hash_free(pd->bind.properties);
   eina_hash_free( pd->bind.factories);

   efl_destructor(efl_super(obj, MY_CLASS));
}

static Eina_Value
_efl_ui_layout_factory_bind(Eo *obj EINA_UNUSED, void *data, const Eina_Value value)
{
   Efl_Ui_Layout_Factory_Data *pd = data;
   Efl_Gfx_Entity *layout;
   int len, i;

   EINA_VALUE_ARRAY_FOREACH(&value, len, i, layout)
     {
        eina_hash_foreach(pd->bind.properties, _property_bind, layout);
        eina_hash_foreach(pd->bind.factories, _factory_bind, layout);

        evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, 0);
        evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
     }

   return value;
}

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);

   efl_ui_factory_building(efl_super(obj, EFL_UI_LAYOUT_FACTORY_CLASS), ui_view);
}

EOLIAN static Eina_Future *
_efl_ui_layout_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Layout_Factory_Data *pd,
                                             Eina_Iterator *models, Efl_Gfx_Entity *parent)
{
   Eina_Future *f;

   f = efl_ui_factory_create(efl_super(obj, EFL_UI_LAYOUT_FACTORY_CLASS), models, parent);

   return efl_future_then(obj, f,
                          .success_type = EINA_VALUE_TYPE_ARRAY,
                          .success = _efl_ui_layout_factory_bind,
                          .data = pd);
}

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)
{
   Eina_Stringshare *ss_key;
   Efl_Ui_Factory *f_old;
   ss_key = eina_stringshare_add(key);

   if (factory == NULL)
     {
        eina_hash_del(pd->bind.factories, ss_key, NULL);
        return;
     }

   f_old = eina_hash_set(pd->bind.factories, ss_key, efl_ref(factory));
   if (f_old)
     {
        efl_unref(f_old);
        eina_stringshare_del(ss_key);
     }
}

EOLIAN static Eina_Error
_efl_ui_layout_factory_efl_ui_property_bind_property_bind(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Factory_Data *pd,
                                                          const char *key, const char *property)
{
   Eina_Stringshare *ss_key, *ss_prop, *ss_old;
   ss_key = eina_stringshare_add(key);

   if (property == NULL)
     {
        eina_hash_del(pd->bind.properties, ss_key, NULL);
        goto end;
     }

   ss_prop = eina_stringshare_add(property);
   ss_old = eina_hash_set(pd->bind.properties, ss_key, ss_prop);
   if (ss_old) eina_stringshare_del(ss_old);
   else ss_key = NULL; // Prevent destruction of key to keep at least one reference

 end:
   efl_event_callback_call(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTY_BOUND, (void*) ss_key);
   eina_stringshare_del(ss_key);
   return 0;
}

EOLIAN static void
_efl_ui_layout_factory_theme_config(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Factory_Data *pd,
                                    const char *klass, const char *group, const char *style)
{
   eina_stringshare_replace(&pd->klass, klass);
   eina_stringshare_replace(&pd->group, group);
   eina_stringshare_replace(&pd->style, style);
}

#include "efl_ui_layout_factory.eo.c"