3 #define SMART_NAME "e_slidesel"
4 #define API_ENTRY E_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)))
5 #define INTERNAL_ENTRY E_Smart_Data *sd; sd = evas_object_smart_data_get(obj); if (!sd) return;
6 typedef struct _E_Smart_Data E_Smart_Data;
7 typedef struct _E_Smart_Item E_Smart_Item;
11 Evas_Coord x, y, w, h;
13 Evas_Object *smart_obj;
14 Evas_Object *edje_obj;
15 Evas_Object *event_obj;
16 Evas_Object *slide_obj;
18 Evas_Coord down_x, down_y;
21 unsigned char down : 1;
22 unsigned char down_cancel : 1;
30 void (*func) (void *data);
34 /* local subsystem functions */
35 static void _e_smart_event_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
36 static void _e_smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
37 static void _e_smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
38 static void _e_smart_event_key_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
39 static void _e_smart_reconfigure(E_Smart_Data *sd);
40 static void _e_smart_add(Evas_Object *obj);
41 static void _e_smart_del(Evas_Object *obj);
42 static void _e_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
43 static void _e_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
44 static void _e_smart_show(Evas_Object *obj);
45 static void _e_smart_hide(Evas_Object *obj);
46 static void _e_smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
47 static void _e_smart_clip_set(Evas_Object *obj, Evas_Object * clip);
48 static void _e_smart_clip_unset(Evas_Object *obj);
49 static void _e_smart_init(void);
51 /* local subsystem globals */
52 static Evas_Smart *_e_smart = NULL;
55 _e_smart_label_change(void *data)
60 edje_object_part_text_set(it->sd->edje_obj, "e.text.label", it->label);
64 /* externally accessible functions */
66 e_slidesel_add(Evas *evas)
69 return evas_object_smart_add(evas, _e_smart);
73 e_slidesel_item_distance_set(Evas_Object *obj, Evas_Coord dist)
76 e_slidecore_item_distance_set(sd->slide_obj, dist);
80 e_slidesel_item_add(Evas_Object *obj, const char *label, const char *icon, void (*func) (void *data), void *data)
85 it = calloc(1, sizeof(E_Smart_Item));
88 if (label) it->label = eina_stringshare_add(label);
89 if (icon) it->icon = eina_stringshare_add(icon);
92 sd->items = eina_list_append(sd->items, it);
93 e_slidecore_item_add(sd->slide_obj, label, icon, _e_smart_label_change, it);
97 e_slidesel_jump(Evas_Object *obj, int num)
100 e_slidecore_jump(sd->slide_obj, num);
103 /* local subsystem functions */
105 _e_smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
107 Evas_Event_Mouse_Down *ev;
114 sd->down_time = ecore_loop_time_get();
117 sd->down_x = ev->canvas.x;
118 sd->down_y = ev->canvas.y;
119 edje_object_signal_emit(sd->edje_obj, "e,state,slide,hint,on", "e");
124 _e_smart_event_mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
126 Evas_Event_Mouse_Down *ev;
133 if (!sd->down_cancel)
135 edje_object_signal_emit(sd->edje_obj, "e,state,slide,hint,off", "e");
136 if (!(ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD))
140 /* get rid of accidental release and presses */
141 // if ((t - sd->down_time) > 0.2)
143 edje_object_signal_emit(sd->edje_obj, "e,action,select", "e");
144 if (sd->cur->func) sd->cur->func(sd->cur->data);
154 _e_smart_event_mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
156 Evas_Event_Mouse_Move *ev;
161 if ((sd->down) && (!sd->down_cancel))
163 Evas_Coord d1, d2, d;
165 d1 = ev->cur.canvas.x - sd->down_x;
166 d2 = ev->cur.canvas.y - sd->down_y;
167 d = (d1 * d1) + (d2 * d2);
170 edje_object_signal_emit(sd->edje_obj, "e,state,slide,hint,off", "e");
177 _e_smart_event_key_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
180 Evas_Event_Key_Down *ev;
185 if (!strcmp(ev->keyname, "Left"))
187 else if (!strcmp(ev->keyname, "Right"))
189 else if (!strcmp(ev->keyname, "Up"))
191 else if (!strcmp(ev->keyname, "Home"))
193 else if (!strcmp(ev->keyname, "End"))
195 else if (!strcmp(ev->keyname, "Down"))
197 else if (!strcmp(ev->keyname, "Prior"))
200 y -= -(sd->page.y * vh) / 100;
204 else if (!strcmp(ev->keyname, "Next"))
207 y += -(sd->page.y * vh) / 100;
215 _e_smart_reconfigure(E_Smart_Data *sd)
217 evas_object_move(sd->edje_obj, sd->x, sd->y);
218 evas_object_resize(sd->edje_obj, sd->w, sd->h);
219 evas_object_move(sd->event_obj, sd->x, sd->y);
220 evas_object_resize(sd->event_obj, sd->w, sd->h);
224 _e_smart_add(Evas_Object *obj)
229 sd = calloc(1, sizeof(E_Smart_Data));
231 evas_object_smart_data_set(obj, sd);
239 evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _e_smart_event_key_down, sd);
240 evas_object_propagate_events_set(obj, 0);
242 o = edje_object_add(evas_object_evas_get(obj));
244 e_theme_edje_object_set(o, "base/theme/widgets",
245 "e/widgets/slidesel");
246 evas_object_smart_member_add(o, obj);
248 o = e_slidecore_add(evas_object_evas_get(obj));
250 edje_object_part_swallow(sd->edje_obj, "e.swallow.content", o);
253 o = evas_object_rectangle_add(evas_object_evas_get(obj));
255 evas_object_color_set(o, 0, 0, 0, 0);
256 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, _e_smart_event_mouse_down, sd);
257 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _e_smart_event_mouse_up, sd);
258 evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE, _e_smart_event_mouse_move, sd);
259 evas_object_smart_member_add(o, obj);
260 evas_object_repeat_events_set(o, 1);
264 _e_smart_del(Evas_Object *obj)
267 evas_object_del(sd->slide_obj);
268 evas_object_del(sd->edje_obj);
269 evas_object_del(sd->event_obj);
274 _e_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
279 _e_smart_reconfigure(sd);
283 _e_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
288 _e_smart_reconfigure(sd);
292 _e_smart_show(Evas_Object *obj)
295 evas_object_show(sd->edje_obj);
296 evas_object_show(sd->event_obj);
300 _e_smart_hide(Evas_Object *obj)
303 evas_object_hide(sd->edje_obj);
304 evas_object_hide(sd->event_obj);
308 _e_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
311 evas_object_color_set(sd->edje_obj, r, g, b, a);
315 _e_smart_clip_set(Evas_Object *obj, Evas_Object * clip)
318 evas_object_clip_set(sd->edje_obj, clip);
319 evas_object_clip_set(sd->event_obj, clip);
323 _e_smart_clip_unset(Evas_Object *obj)
326 evas_object_clip_unset(sd->edje_obj);
327 evas_object_clip_unset(sd->event_obj);
330 /* never need to touch this */
335 if (_e_smart) return;
337 static const Evas_Smart_Class sc =
340 EVAS_SMART_CLASS_VERSION,
358 _e_smart = evas_smart_class_new(&sc);