aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ecore/efl_composite_model_private.h
blob: 67862f968c86067326705940fa9495b38ab8fa6b (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
#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