move around - flatter.
[profile/ivi/evas.git] / src / lib / canvas / evas_smart.c
1 #include "evas_common.h"
2 #include "evas_private.h"
3
4 /* all public */
5
6 /**
7  * @defgroup Evas_Smart_Group Evas Smart Functions
8  *
9  * Functions that deal with Evas_Smart's.
10  *
11  */
12
13 /**
14  * Create an Evas_Smart, which can be used to instantiate new smart objects.
15  *
16  * This function internally creates an Evas_Smart_Class and sets the
17  * provided callbacks. Callbacks that are unneeded (or marked DEPRECATED
18  * below) should be set to NULL.
19  *
20  * Alternatively you can create an Evas_Smart_Class yourself and use 
21  * evas_smart_class_new().
22  *
23  * @param name a unique name for the smart
24  * @param func_add callback called when smart object is added
25  * @param func_del callback called when smart object is deleted
26  * @param func_layer_set DEPRECATED
27  * @param func_raise DEPRECATED
28  * @param func_lower DEPRECATED
29  * @param func_stack_above DEPRECATED
30  * @param func_stack_below DEPRECATED
31  * @param func_move callback called when smart object is moved 
32  * @param func_resize callback called when smart object is resized 
33  * @param func_show callback called when smart object is shown
34  * @param func_hide callback called when smart object is hidden
35  * @param func_color_set callback called when smart object has its color set
36  * @param func_clip_set callback called when smart object has its clip set
37  * @param func_clip_unset callback called when smart object has its clip unset
38  * @param data a pointer to user data for the smart
39  * @return an Evas_Smart
40  *
41  */
42 EAPI Evas_Smart *
43 evas_smart_new(const char *name,
44                void      (*func_add) (Evas_Object *o),
45                void      (*func_del) (Evas_Object *o),
46                void      (*func_layer_set) (Evas_Object *o, int l),
47                void      (*func_raise) (Evas_Object *o),
48                void      (*func_lower) (Evas_Object *o),
49                void      (*func_stack_above) (Evas_Object *o, Evas_Object *above),
50                void      (*func_stack_below) (Evas_Object *o, Evas_Object *below),
51                void      (*func_move) (Evas_Object *o, Evas_Coord x, Evas_Coord y),
52                void      (*func_resize) (Evas_Object *o, Evas_Coord w, Evas_Coord h),
53                void      (*func_show) (Evas_Object *o),
54                void      (*func_hide) (Evas_Object *o),
55                void      (*func_color_set) (Evas_Object *o, int r, int g, int b, int a),
56                void      (*func_clip_set) (Evas_Object *o, Evas_Object *clip),
57                void      (*func_clip_unset) (Evas_Object *o),
58                const void *data)
59 {
60    Evas_Smart *s;
61    Evas_Smart_Class *sc;
62
63    printf("----- WARNING. evas_smart_new() will be deprecated and removed soon\n"
64           "----- Please use evas_smart_class_new() instead\n");
65    
66    if (!name) return NULL;
67
68    s = evas_mem_calloc(sizeof(Evas_Smart));
69    if (!s) return NULL;
70
71    s->magic = MAGIC_SMART;
72
73    s->class_allocated = 1;
74
75    sc = evas_mem_calloc(sizeof(Evas_Smart_Class));
76    if (!sc)
77      {
78         free(s);
79         return NULL;
80      }
81    sc->name = name;
82    sc->add = func_add;
83    sc->del = func_del;
84    sc->move = func_move;
85    sc->resize = func_resize;
86    sc->show = func_show;
87    sc->hide = func_hide;
88    sc->color_set = func_color_set;
89    sc->clip_set = func_clip_set;
90    sc->clip_unset = func_clip_unset;
91    sc->data = (void *)data;
92    s->smart_class = sc;
93
94    return s;
95 }
96
97 /**
98  * Free an Evas_Smart
99  *
100  * If this smart was created using evas_smart_class_new(), the associated
101  * Evas_Smart_Class will not be freed.
102  *
103  * @param s the Evas_Smart to free
104  *
105  */
106 EAPI void
107 evas_smart_free(Evas_Smart *s)
108 {
109    MAGIC_CHECK(s, Evas_Smart, MAGIC_SMART);
110    return;
111    MAGIC_CHECK_END();
112    s->delete_me = 1;
113    if (s->usage > 0) return;
114    if (s->class_allocated) free((void *)s->smart_class);
115    free(s);
116 }
117
118 /**
119  * Creates an Evas_Smart from an Evas_Smart_Class.
120  *
121  * @param Evas_Smart_Class the smart class definition
122  * @return an Evas_Smart
123  */
124 EAPI Evas_Smart *
125 evas_smart_class_new(const Evas_Smart_Class *sc)
126 {
127    Evas_Smart *s;
128
129    if (!sc) return NULL;
130
131    /* api does not match abi! for now refuse as we only have 1 version */
132    if (sc->version != EVAS_SMART_CLASS_VERSION) return NULL;
133    
134    s = evas_mem_calloc(sizeof(Evas_Smart));
135    if (!s) return NULL;
136
137    s->magic = MAGIC_SMART;
138
139    s->smart_class = sc;
140
141    return s;
142 }
143
144 /**
145  * Get the Evas_Smart_Class of an Evas_Smart
146  *
147  * @param s the Evas_Smart
148  * @return the Evas_Smart_Class
149  */
150 EAPI const Evas_Smart_Class *
151 evas_smart_class_get(const Evas_Smart *s)
152 {
153    MAGIC_CHECK(s, Evas_Smart, MAGIC_SMART);
154    return NULL;
155    MAGIC_CHECK_END();
156    return s->smart_class;
157 }
158
159 /**
160  * Get the data pointer set on an Evas_Smart.
161  *
162  * This data pointer is set either as the final parameter to 
163  * evas_smart_new or as the data field in the Evas_Smart_Class passed
164  * in to evas_smart_class_new
165  *
166  * @param Evas_Smart 
167  *
168  */
169 EAPI void *
170 evas_smart_data_get(const Evas_Smart *s)
171 {
172    MAGIC_CHECK(s, Evas_Smart, MAGIC_SMART);
173    return NULL;
174    MAGIC_CHECK_END();
175    return (void *)s->smart_class->data;
176 }
177
178 /* internal funcs */
179 void
180 evas_object_smart_use(Evas_Smart *s)
181 {
182    s->usage++;
183 }
184
185 void
186 evas_object_smart_unuse(Evas_Smart *s)
187 {
188    s->usage--;
189    if ((s->usage <= 0) && (s->delete_me)) evas_smart_free(s);
190 }