evas: mega documentation improving commit.
[profile/ivi/evas.git] / src / lib / canvas / evas_layer.c
1 #include "evas_common.h"
2 #include "evas_private.h"
3
4 static void _evas_layer_free(Evas_Layer *lay);
5
6 void
7 evas_object_inject(Evas_Object *obj, Evas *e)
8 {
9    Evas_Layer *lay;
10
11    if (obj->in_layer) return;
12    lay = evas_layer_find(e, obj->cur.layer);
13    if (!lay)
14      {
15         lay = evas_layer_new(e);
16         lay->layer = obj->cur.layer;
17         evas_layer_add(lay);
18      }
19    lay->objects = (Evas_Object *)eina_inlist_append(EINA_INLIST_GET(lay->objects), EINA_INLIST_GET(obj));
20    lay->usage++;
21    obj->layer = lay;
22    obj->in_layer = 1;
23 }
24
25 void
26 evas_object_release(Evas_Object *obj, int clean_layer)
27 {
28    if (!obj->in_layer) return;
29    obj->layer->objects = (Evas_Object *)eina_inlist_remove(EINA_INLIST_GET(obj->layer->objects), EINA_INLIST_GET(obj));
30    obj->layer->usage--;
31    if (clean_layer)
32      {
33         if (obj->layer->usage <= 0)
34           {
35              evas_layer_del(obj->layer);
36              _evas_layer_free(obj->layer);
37           }
38      }
39    obj->layer = NULL;
40    obj->in_layer = 0;
41 }
42
43 Evas_Layer *
44 evas_layer_new(Evas *e)
45 {
46    Evas_Layer *lay;
47
48    lay = calloc(1, sizeof(Evas_Layer));
49    if (!lay) return NULL;
50    lay->evas = e;
51    return lay;
52 }
53
54 static void
55 _evas_layer_free(Evas_Layer *lay)
56 {
57    free(lay);
58 }
59
60 void
61 evas_layer_pre_free(Evas_Layer *lay)
62 {
63    Evas_Object *obj;
64
65    EINA_INLIST_FOREACH(lay->objects, obj)
66      {
67         if ((!obj->smart.parent) && (!obj->delete_me))
68           evas_object_del(obj);
69      }
70 }
71
72 void
73 evas_layer_free_objects(Evas_Layer *lay)
74 {
75    while (lay->objects)
76      {
77         Evas_Object *obj;
78
79         obj = (Evas_Object *)lay->objects;
80         evas_object_free(obj, 0);
81      }
82 }
83
84 void
85 evas_layer_clean(Evas *e)
86 {
87    Evas_Layer *tmp;
88
89    while (e->layers)
90      {
91         tmp = e->layers;
92         evas_layer_del(tmp);
93         _evas_layer_free(tmp);
94      }
95 }
96
97 Evas_Layer *
98 evas_layer_find(Evas *e, short layer_num)
99 {
100    Evas_Layer *layer;
101
102    EINA_INLIST_FOREACH(e->layers, layer)
103      {
104         if (layer->layer == layer_num) return layer;
105      }
106    return NULL;
107 }
108
109 void
110 evas_layer_add(Evas_Layer *lay)
111 {
112    Evas_Layer *layer;
113
114    EINA_INLIST_FOREACH(lay->evas->layers, layer)
115      {
116         if (layer->layer > lay->layer)
117           {
118              lay->evas->layers = (Evas_Layer *)eina_inlist_prepend_relative(EINA_INLIST_GET(lay->evas->layers),
119                                                                             EINA_INLIST_GET(lay),
120                                                                             EINA_INLIST_GET(layer));
121              return;
122           }
123      }
124    lay->evas->layers = (Evas_Layer *)eina_inlist_append(EINA_INLIST_GET(lay->evas->layers), EINA_INLIST_GET(lay));
125 }
126
127 void
128 evas_layer_del(Evas_Layer *lay)
129 {
130    Evas *e;
131
132    e = lay->evas;
133    e->layers = (Evas_Layer *)eina_inlist_remove(EINA_INLIST_GET(e->layers), EINA_INLIST_GET(lay));
134 }
135
136 /* public functions */
137
138 /**
139  * @addtogroup Evas_Object_Group_Basic
140  * @{
141  */
142
143 /**
144  * Sets the layer of the evas that the given object will be part of.
145  *
146  * It is not possible to change the layer of a smart object's child.
147  *
148  * @param   obj The given evas object.
149  * @param   l   The number of the layer to place the object on.
150  *          Between #EVAS_LAYER_MIN and #EVAS_LAYER_MAX.
151  */
152 EAPI void
153 evas_object_layer_set(Evas_Object *obj, short l)
154 {
155    Evas *e;
156
157    MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
158    return;
159    MAGIC_CHECK_END();
160    if (evas_object_intercept_call_layer_set(obj, l)) return;
161    if (obj->smart.parent) return;
162    if (obj->cur.layer == l)
163      {
164         evas_object_raise(obj);
165         return;
166      }
167    e = obj->layer->evas;
168    evas_object_release(obj, 1);
169    obj->cur.layer = l;
170    evas_object_inject(obj, e);
171    obj->restack = 1;
172    evas_object_change(obj);
173    if (obj->clip.clipees)
174      {
175         evas_object_inform_call_restack(obj);
176         return;
177      }
178    evas_object_change(obj);
179    if (!obj->smart.smart)
180      {
181         if (evas_object_is_in_output_rect(obj,
182                                           obj->layer->evas->pointer.x,
183                                           obj->layer->evas->pointer.y, 1, 1) &&
184             obj->cur.visible)
185           if (eina_list_data_find(obj->layer->evas->pointer.object.in, obj))
186             evas_event_feed_mouse_move(obj->layer->evas,
187                                        obj->layer->evas->pointer.x,
188                                        obj->layer->evas->pointer.y,
189                                        obj->layer->evas->last_timestamp,
190                                        NULL);
191      }
192    evas_object_inform_call_restack(obj);
193 }
194
195 /**
196  * Retrieves the layer of the evas that the given object is part of.
197  *
198  * Be carefull, it doesn't make sense to change the layer of smart object's
199  * child. So the returned value could be wrong in some case. Don't rely on
200  * it's accuracy.
201  *
202  * @param   obj The given evas object.
203  * @return  Number of the layer.
204  */
205 EAPI short
206 evas_object_layer_get(const Evas_Object *obj)
207 {
208    MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
209    return 0;
210    MAGIC_CHECK_END();
211    if (obj->smart.parent)
212      {
213         return obj->smart.parent->cur.layer;
214      }
215    return obj->cur.layer;
216 }
217
218 /**
219  * @}
220  */