create rotation job and EAPI e_border_rotation_set
[platform/core/uifw/e17.git] / src / bin / e_slidesel.c
1 #include "e.h"
2
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;
8
9 struct _E_Smart_Data
10 {
11    Evas_Coord   x, y, w, h;
12
13    Evas_Object *smart_obj;
14    Evas_Object *edje_obj;
15    Evas_Object *event_obj;
16    Evas_Object *slide_obj;
17    Eina_List *items;
18    Evas_Coord down_x, down_y;
19    E_Smart_Item *cur;
20    double down_time;
21    unsigned char down : 1;
22    unsigned char down_cancel : 1;
23 };
24
25 struct _E_Smart_Item
26 {
27    E_Smart_Data *sd;
28    const char *label;
29    const char *icon;
30    void (*func) (void *data);
31    void *data;
32 };
33
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);
50
51 /* local subsystem globals */
52 static Evas_Smart *_e_smart = NULL;
53
54 static void
55 _e_smart_label_change(void *data)
56 {
57    E_Smart_Item *it;
58
59    it = data;
60    edje_object_part_text_set(it->sd->edje_obj, "e.text.label", it->label);
61    it->sd->cur = it;
62 }
63
64 /* externally accessible functions */
65 EAPI Evas_Object *
66 e_slidesel_add(Evas *evas)
67 {
68    _e_smart_init();
69    return evas_object_smart_add(evas, _e_smart);
70 }
71
72 EAPI void
73 e_slidesel_item_distance_set(Evas_Object *obj, Evas_Coord dist)
74 {
75    API_ENTRY return;
76    e_slidecore_item_distance_set(sd->slide_obj, dist);
77 }
78
79 EAPI void
80 e_slidesel_item_add(Evas_Object *obj, const char *label, const char *icon, void (*func) (void *data), void *data)
81 {
82    E_Smart_Item *it;
83
84    API_ENTRY return;
85    it = calloc(1, sizeof(E_Smart_Item));
86    if (!it) return;
87    it->sd = sd;
88    if (label) it->label = eina_stringshare_add(label);
89    if (icon) it->icon = eina_stringshare_add(icon);
90    it->func = func;
91    it->data = data;
92    sd->items = eina_list_append(sd->items, it);
93    e_slidecore_item_add(sd->slide_obj, label, icon, _e_smart_label_change, it);
94 }
95
96 EAPI void
97 e_slidesel_jump(Evas_Object *obj, int num)
98 {
99    API_ENTRY return;
100    e_slidecore_jump(sd->slide_obj, num);
101 }
102
103 /* local subsystem functions */
104 static void
105 _e_smart_event_mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
106 {
107    Evas_Event_Mouse_Down *ev;
108    E_Smart_Data *sd;
109
110    sd = data;
111    ev = event_info;
112    if (ev->button == 1)
113      {
114         sd->down_time = ecore_loop_time_get();
115         sd->down = 1;
116         sd->down_cancel = 0;
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");
120      }
121 }
122
123 static void
124 _e_smart_event_mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
125 {
126    Evas_Event_Mouse_Down *ev;
127    E_Smart_Data *sd;
128
129    sd = data;
130    ev = event_info;
131    if (ev->button == 1)
132      {
133         if (!sd->down_cancel)
134           {
135              edje_object_signal_emit(sd->edje_obj, "e,state,slide,hint,off", "e");
136              if (!(ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD))
137                {
138                   if (sd->cur)
139                     {
140                        /* get rid of accidental release and presses */
141 //                     if ((t - sd->down_time) > 0.2)
142                          {
143                             edje_object_signal_emit(sd->edje_obj, "e,action,select", "e");
144                             if (sd->cur->func) sd->cur->func(sd->cur->data);
145                          }
146                     }
147                }
148           }
149         sd->down = 0;
150      }
151 }
152
153 static void
154 _e_smart_event_mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
155 {
156    Evas_Event_Mouse_Move *ev;
157    E_Smart_Data *sd;
158
159    sd = data;
160    ev = event_info;
161    if ((sd->down) && (!sd->down_cancel))
162      {
163         Evas_Coord d1, d2, d;
164
165         d1 = ev->cur.canvas.x - sd->down_x;
166         d2 = ev->cur.canvas.y - sd->down_y;
167         d = (d1 * d1) + (d2 * d2);
168         if (d > (64 * 64))
169           {
170              edje_object_signal_emit(sd->edje_obj, "e,state,slide,hint,off", "e");
171              sd->down_cancel = 1;
172           }
173      }
174 }
175
176 static void
177 _e_smart_event_key_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
178 {
179 /*
180    Evas_Event_Key_Down *ev;
181    E_Smart_Data *sd;
182
183    sd = data;
184    ev = event_info;
185    if (!strcmp(ev->keyname, "Left"))
186      x -= sd->step.x;
187    else if (!strcmp(ev->keyname, "Right"))
188      x += sd->step.x;
189    else if (!strcmp(ev->keyname, "Up"))
190      y -= sd->step.y;
191    else if (!strcmp(ev->keyname, "Home"))
192      y = 0;
193    else if (!strcmp(ev->keyname, "End"))
194      y = my;
195    else if (!strcmp(ev->keyname, "Down"))
196      y += sd->step.y;
197    else if (!strcmp(ev->keyname, "Prior"))
198      {
199         if (sd->page.y < 0)
200           y -= -(sd->page.y * vh) / 100;
201         else
202           y -= sd->page.y;
203      }
204    else if (!strcmp(ev->keyname, "Next"))
205      {
206         if (sd->page.y < 0)
207           y += -(sd->page.y * vh) / 100;
208         else
209           y += sd->page.y;
210      }
211  */
212 }
213
214 static void
215 _e_smart_reconfigure(E_Smart_Data *sd)
216 {
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);
221 }
222
223 static void
224 _e_smart_add(Evas_Object *obj)
225 {
226    E_Smart_Data *sd;
227    Evas_Object *o;
228
229    sd = calloc(1, sizeof(E_Smart_Data));
230    if (!sd) return;
231    evas_object_smart_data_set(obj, sd);
232
233    sd->smart_obj = obj;
234    sd->x = 0;
235    sd->y = 0;
236    sd->w = 0;
237    sd->h = 0;
238
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);
241
242    o = edje_object_add(evas_object_evas_get(obj));
243    sd->edje_obj = o;
244    e_theme_edje_object_set(o, "base/theme/widgets",
245                            "e/widgets/slidesel");
246    evas_object_smart_member_add(o, obj);
247
248    o = e_slidecore_add(evas_object_evas_get(obj));
249    sd->slide_obj = o;
250    edje_object_part_swallow(sd->edje_obj, "e.swallow.content", o);
251    evas_object_show(o);
252
253    o = evas_object_rectangle_add(evas_object_evas_get(obj));
254    sd->event_obj = o;
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);
261 }
262
263 static void
264 _e_smart_del(Evas_Object *obj)
265 {
266    INTERNAL_ENTRY;
267    evas_object_del(sd->slide_obj);
268    evas_object_del(sd->edje_obj);
269    evas_object_del(sd->event_obj);
270    free(sd);
271 }
272
273 static void
274 _e_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
275 {
276    INTERNAL_ENTRY;
277    sd->x = x;
278    sd->y = y;
279    _e_smart_reconfigure(sd);
280 }
281
282 static void
283 _e_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
284 {
285    INTERNAL_ENTRY;
286    sd->w = w;
287    sd->h = h;
288    _e_smart_reconfigure(sd);
289 }
290
291 static void
292 _e_smart_show(Evas_Object *obj)
293 {
294    INTERNAL_ENTRY;
295    evas_object_show(sd->edje_obj);
296    evas_object_show(sd->event_obj);
297 }
298
299 static void
300 _e_smart_hide(Evas_Object *obj)
301 {
302    INTERNAL_ENTRY;
303    evas_object_hide(sd->edje_obj);
304    evas_object_hide(sd->event_obj);
305 }
306
307 static void
308 _e_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
309 {
310    INTERNAL_ENTRY;
311    evas_object_color_set(sd->edje_obj, r, g, b, a);
312 }
313
314 static void
315 _e_smart_clip_set(Evas_Object *obj, Evas_Object * clip)
316 {
317    INTERNAL_ENTRY;
318    evas_object_clip_set(sd->edje_obj, clip);
319    evas_object_clip_set(sd->event_obj, clip);
320 }
321
322 static void
323 _e_smart_clip_unset(Evas_Object *obj)
324 {
325    INTERNAL_ENTRY;
326    evas_object_clip_unset(sd->edje_obj);
327    evas_object_clip_unset(sd->event_obj);
328 }
329
330 /* never need to touch this */
331
332 static void
333 _e_smart_init(void)
334 {
335    if (_e_smart) return;
336      {
337         static const Evas_Smart_Class sc =
338           {
339              SMART_NAME,
340                EVAS_SMART_CLASS_VERSION,
341                _e_smart_add,
342                _e_smart_del,
343                _e_smart_move,
344                _e_smart_resize,
345                _e_smart_show,
346                _e_smart_hide,
347                _e_smart_color_set,
348                _e_smart_clip_set,
349                _e_smart_clip_unset,
350                NULL,
351                NULL,
352                NULL,
353                NULL,
354                NULL,
355                NULL,
356                NULL
357           };
358         _e_smart = evas_smart_class_new(&sc);
359      }
360 }