1 #include <Elementary.h>
4 #define SMART_NAME "elm_pan"
5 #define API_ENTRY Smart_Data *sd; sd = evas_object_smart_data_get(obj); if ((!obj) || (!sd) || (evas_object_type_get(obj) && strcmp(evas_object_type_get(obj), SMART_NAME)))
6 #define INTERNAL_ENTRY Smart_Data *sd; sd = evas_object_smart_data_get(obj); if (!sd) return;
7 typedef struct _Smart_Data Smart_Data;
11 Evas_Object *smart_obj;
12 Evas_Object *child_obj;
13 Evas_Coord x, y, w, h;
14 Evas_Coord child_w, child_h, px, py;
17 /* local subsystem functions */
18 static void _smart_child_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
19 static void _smart_child_resize_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
21 static void _smart_reconfigure(Smart_Data *sd);
22 static void _smart_add(Evas_Object *obj);
23 static void _smart_del(Evas_Object *obj);
24 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
25 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
26 static void _smart_show(Evas_Object *obj);
27 static void _smart_hide(Evas_Object *obj);
28 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
29 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
30 static void _smart_clip_unset(Evas_Object *obj);
31 static void _smart_init(void);
33 /* local subsystem globals */
34 static Evas_Smart *_smart = NULL;
36 /* externally accessible functions */
38 _elm_smart_pan_add(Evas *evas)
41 return evas_object_smart_add(evas, _smart);
45 _elm_smart_pan_child_set(Evas_Object *obj, Evas_Object *child)
48 if (child == sd->child_obj) return;
51 evas_object_clip_unset(sd->child_obj);
52 evas_object_smart_member_del(sd->child_obj);
53 evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_FREE, _smart_child_del_hook, sd);
54 evas_object_event_callback_del_full(sd->child_obj, EVAS_CALLBACK_RESIZE, _smart_child_resize_hook, sd);
62 sd->child_obj = child;
63 evas_object_smart_member_add(sd->child_obj, sd->smart_obj);
64 evas_object_geometry_get(sd->child_obj, NULL, NULL, &w, &h);
67 evas_object_event_callback_add(child, EVAS_CALLBACK_FREE, _smart_child_del_hook, sd);
68 evas_object_event_callback_add(child, EVAS_CALLBACK_RESIZE, _smart_child_resize_hook, sd);
69 evas_object_color_get(sd->smart_obj, &r, &g, &b, &a);
70 evas_object_color_set(sd->child_obj, r, g, b, a);
71 evas_object_clip_set(sd->child_obj, evas_object_clip_get(sd->smart_obj));
72 if (evas_object_visible_get(sd->smart_obj)) evas_object_show(sd->child_obj);
73 else evas_object_hide(sd->child_obj);
74 _smart_reconfigure(sd);
76 evas_object_smart_callback_call(sd->smart_obj, "changed", NULL);
80 _elm_smart_pan_child_get(Evas_Object *obj)
82 API_ENTRY return NULL;
87 _elm_smart_pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
90 // if (x > (sd->child_w - sd->w)) x = sd->child_w - sd->w;
91 // if (y > (sd->child_h - sd->h)) y = sd->child_h - sd->h;
94 if ((x == sd->px) && (y == sd->py)) return;
97 _smart_reconfigure(sd);
98 evas_object_smart_callback_call(sd->smart_obj, "changed", NULL);
102 _elm_smart_pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
110 _elm_smart_pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
115 if (sd->w < sd->child_w) *x = sd->child_w - sd->w;
120 if (sd->h < sd->child_h) *y = sd->child_h - sd->h;
126 _elm_smart_pan_min_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
136 _elm_smart_pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
139 if (w) *w = sd->child_w;
140 if (h) *h = sd->child_h;
143 /* local subsystem functions */
145 _smart_child_del_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
150 sd->child_obj = NULL;
151 evas_object_smart_callback_call(sd->smart_obj, "changed", NULL);
155 _smart_child_resize_hook(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
161 evas_object_geometry_get(sd->child_obj, NULL, NULL, &w, &h);
162 if ((w != sd->child_w) || (h != sd->child_h))
166 _smart_reconfigure(sd);
168 evas_object_smart_callback_call(sd->smart_obj, "changed", NULL);
172 _smart_reconfigure(Smart_Data *sd)
174 evas_object_move(sd->child_obj, sd->x - sd->px, sd->y - sd->py);
178 _smart_add(Evas_Object *obj)
182 sd = calloc(1, sizeof(Smart_Data));
189 evas_object_smart_data_set(obj, sd);
193 _smart_del(Evas_Object *obj)
196 _elm_smart_pan_child_set(obj, NULL);
201 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
206 _smart_reconfigure(sd);
210 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
215 _smart_reconfigure(sd);
216 evas_object_smart_callback_call(sd->smart_obj, "changed", NULL);
220 _smart_show(Evas_Object *obj)
224 evas_object_show(sd->child_obj);
228 _smart_hide(Evas_Object *obj)
232 evas_object_hide(sd->child_obj);
236 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
240 evas_object_color_set(sd->child_obj, r, g, b, a);
244 _smart_clip_set(Evas_Object *obj, Evas_Object *clip)
248 evas_object_clip_set(sd->child_obj, clip);
252 _smart_clip_unset(Evas_Object *obj)
256 evas_object_clip_unset(sd->child_obj);
259 /* never need to touch this */
266 static const Evas_Smart_Class sc =
269 EVAS_SMART_CLASS_VERSION,
287 _smart = evas_smart_class_new(&sc);