1 #include "evas_common.h"
2 #include "evas_private.h"
7 * @defgroup Evas_Smart_Group Evas Smart Functions
9 * Functions that deal with Evas_Smart's.
14 * Create an Evas_Smart, which can be used to instantiate new smart objects.
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.
20 * Alternatively you can create an Evas_Smart_Class yourself and use
21 * evas_smart_class_new().
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
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),
63 printf("----- WARNING. evas_smart_new() will be deprecated and removed soon\n"
64 "----- Please use evas_smart_class_new() instead\n");
66 if (!name) return NULL;
68 s = evas_mem_calloc(sizeof(Evas_Smart));
71 s->magic = MAGIC_SMART;
73 s->class_allocated = 1;
75 sc = evas_mem_calloc(sizeof(Evas_Smart_Class));
85 sc->resize = func_resize;
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;
100 * If this smart was created using evas_smart_class_new(), the associated
101 * Evas_Smart_Class will not be freed.
103 * @param s the Evas_Smart to free
107 evas_smart_free(Evas_Smart *s)
109 MAGIC_CHECK(s, Evas_Smart, MAGIC_SMART);
113 if (s->usage > 0) return;
114 if (s->class_allocated) free((void *)s->smart_class);
119 * Creates an Evas_Smart from an Evas_Smart_Class.
121 * @param Evas_Smart_Class the smart class definition
122 * @return an Evas_Smart
125 evas_smart_class_new(const Evas_Smart_Class *sc)
129 if (!sc) return NULL;
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;
134 s = evas_mem_calloc(sizeof(Evas_Smart));
137 s->magic = MAGIC_SMART;
145 * Get the Evas_Smart_Class of an Evas_Smart
147 * @param s the Evas_Smart
148 * @return the Evas_Smart_Class
150 EAPI const Evas_Smart_Class *
151 evas_smart_class_get(const Evas_Smart *s)
153 MAGIC_CHECK(s, Evas_Smart, MAGIC_SMART);
156 return s->smart_class;
160 * Get the data pointer set on an Evas_Smart.
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
170 evas_smart_data_get(const Evas_Smart *s)
172 MAGIC_CHECK(s, Evas_Smart, MAGIC_SMART);
175 return (void *)s->smart_class->data;
180 evas_object_smart_use(Evas_Smart *s)
186 evas_object_smart_unuse(Evas_Smart *s)
189 if ((s->usage <= 0) && (s->delete_me)) evas_smart_free(s);