elementary: support build without Ecore_IMF and/or without Ecore_Con.
[framework/uifw/elementary.git] / src / lib / elm_map.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #include "Elementary.h"
6 #include "elm_priv.h"
7 #include "els_scroller.h"
8
9 #ifdef HAVE_ELEMENTARY_ECORE_CON
10
11 typedef struct _Widget_Data Widget_Data;
12 typedef struct _Pan Pan;
13 typedef struct _Grid Grid;
14 typedef struct _Grid_Item Grid_Item;
15 typedef struct _Marker_Group Marker_Group;
16 typedef struct _Event Event;
17 typedef struct _Path_Node Path_Node;
18 typedef struct _Path_Waypoint Path_Waypoint;
19 typedef struct _Url_Data Url_Data;
20 typedef struct _Route_Dump Route_Dump;
21 typedef struct _Name_Dump Name_Dump;
22 typedef struct _Track_Dump Track_Dump;
23
24 #define DEST_DIR_ZOOM_PATH "/tmp/elm_map/%d/%d/"
25 #define DEST_DIR_PATH DEST_DIR_ZOOM_PATH"%d/"
26 #define DEST_FILE_PATH "%s%d.png"
27 #define DEST_ROUTE_XML_FILE "/tmp/elm_map-route-XXXXXX"
28 #define DEST_NAME_XML_FILE "/tmp/elm_map-name-XXXXXX"
29
30 #define ROUTE_YOURS_URL "http://www.yournavigation.org/api/dev/route.php"
31 #define ROUTE_TYPE_MOTORCAR "motocar"
32 #define ROUTE_TYPE_BICYCLE "bicycle"
33 #define ROUTE_TYPE_FOOT "foot"
34 #define YOURS_DISTANCE "distance"
35 #define YOURS_DESCRIPTION "description"
36 #define YOURS_COORDINATES "coordinates"
37
38 // TODO: fix monav & ors url
39 #define ROUTE_MONAV_URL "http://"
40 #define ROUTE_ORS_URL "http:///"
41
42 #define NAME_NOMINATIM_URL "http://nominatim.openstreetmap.org"
43 #define NOMINATIM_RESULT "result"
44 #define NOMINATIM_PLACE "place"
45 #define NOMINATIM_ATTR_LON "lon"
46 #define NOMINATIM_ATTR_LAT "lat"
47
48 #define PINCH_ZOOM_MIN 0.25
49 #define PINCH_ZOOM_MAX 4.0
50 #define MAX_CONCURRENT_DOWNLOAD 10
51
52 #define GPX_NAME "name>"
53 #define GPX_COORDINATES "trkpt "
54 #define GPX_LON "lon"
55 #define GPX_LAT "lat"
56 #define GPX_ELE "ele>"
57 #define GPX_TIME "time>"
58
59 // Map sources
60 // Currently the size of a tile must be 256*256
61 // and the size of the map must be pow(2.0, z)*tile_size
62 typedef struct _Map_Sources_Tab
63 {
64    const char *name;
65    int zoom_min;
66    int zoom_max;
67    ElmMapModuleUrlFunc url_cb;
68    Elm_Map_Route_Sources route_source;
69    ElmMapModuleRouteUrlFunc route_url_cb;
70    ElmMapModuleNameUrlFunc name_url_cb;
71    ElmMapModuleGeoIntoCoordFunc geo_into_coord;
72    ElmMapModuleCoordIntoGeoFunc coord_into_geo;
73 } Map_Sources_Tab;
74
75 //Zemm min is supposed to be 0
76 static char *_mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
77 static char *_osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
78 static char *_cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
79 static char *_maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom);
80
81 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
82 /*
83 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
84 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat);
85  */
86 static char *_nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat);
87
88 static Map_Sources_Tab default_map_sources_tab[] =
89 {
90      {"Mapnik", 0, 18, _mapnik_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
91      {"Osmarender", 0, 17, _osmarender_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
92      {"CycleMap", 0, 17, _cyclemap_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
93      {"Maplint", 12, 16, _maplint_url_cb, ELM_MAP_ROUTE_SOURCE_YOURS, _yours_url_cb, _nominatim_url_cb, NULL, NULL},
94 };
95
96 struct _Url_Data
97 {
98    Ecore_Con_Url *con_url;
99
100    FILE *fd;
101    char *fname;
102 };
103
104 struct _Elm_Map_Marker_Class
105 {
106    const char *style;
107    int zoom_displayed;
108
109    struct _Elm_Map_Marker_Class_Func {
110         ElmMapMarkerGetFunc get;
111         ElmMapMarkerDelFunc del; //if NULL the object will be destroyed with evas_object_del()
112         ElmMapMarkerIconGetFunc icon_get;
113    } func;
114
115    struct { //this part is private, do not modify these values
116         Eina_Bool set : 1;
117         Evas_Coord edje_w, edje_h;
118    } priv;
119 };
120
121 struct _Elm_Map_Marker
122 {
123    Widget_Data *wd;
124    Elm_Map_Marker_Class *clas;
125    Elm_Map_Group_Class *clas_group;
126    double longitude, latitude;
127
128    Evas_Coord map_size;
129    Evas_Coord *x, *y;
130    void *data;
131    Marker_Group **groups;
132    Evas_Object *content;
133 };
134
135 struct _Elm_Map_Group_Class
136 {
137    const char *style;
138    void *data;
139    int zoom_displayed; // display the group if the zoom is >= to zoom_display
140    int zoom_grouped; // group the markers only if the zoom is <= to zoom_groups
141    Eina_Bool hide : 1;
142
143    struct {
144         ElmMapGroupIconGetFunc icon_get;
145    } func;
146
147    struct { //this part is private, do not modify these values
148         Eina_Bool set : 1;
149         Evas_Coord edje_w, edje_h;
150         Evas_Coord edje_max_w, edje_max_h;
151
152         Eina_List *objs_used;
153         Eina_List *objs_notused;
154    } priv;
155 };
156
157 struct _Marker_Group
158 {
159    Widget_Data *wd;
160    Eina_Matrixsparse_Cell *cell;
161    Elm_Map_Group_Class *clas;
162
163    Eina_List *markers;
164    long long sum_x, sum_y;
165    Evas_Coord x, y;
166    Evas_Coord w, h;
167
168    Evas_Object *obj, *bubble, *sc, *bx, *rect;
169    Eina_Bool open : 1;
170    Eina_Bool bringin : 1;
171    Eina_Bool update_nbelems : 1;
172    Eina_Bool update_resize : 1;
173    Eina_Bool update_raise : 1;
174    Eina_Bool delete_object : 1;
175 };
176
177 struct _Elm_Map_Route
178 {
179    Widget_Data *wd;
180
181    Path_Node *n;
182    Path_Waypoint *w;
183    Ecore_Con_Url *con_url;
184
185    int type;
186    int method;
187    int x, y;
188    double flon, flat, tlon, tlat;
189
190    Eina_List *nodes, *path;
191    Eina_List *waypoint;
192
193    struct {
194       int node_count;
195       int waypoint_count;
196       const char *nodes;
197       const char *waypoints;
198       double distance; /* unit : km */
199    } info;
200
201    Eina_List *handlers;
202    Url_Data ud;
203
204    struct {
205       int r;
206       int g;
207       int b;
208       int a;
209    } color;
210
211    Eina_Bool inbound : 1;
212 };
213
214 struct _Path_Node
215 {
216    Widget_Data *wd;
217
218    int idx;
219    struct {
220       double lon, lat;
221       char *address;
222    } pos;
223 };
224
225 struct _Path_Waypoint
226 {
227    Widget_Data *wd;
228
229    const char *point;
230 };
231
232 struct _Elm_Map_Name
233 {
234    Widget_Data *wd;
235
236    Ecore_Con_Url *con_url;
237    int method;
238    char *address;
239    double lon, lat;
240    Url_Data ud;
241    Ecore_Event_Handler *handler;
242 };
243
244 struct _Grid_Item
245 {
246    Widget_Data *wd;
247    Grid *g;
248    Evas_Object *img;
249    //Evas_Object *txt;
250    const char *file;
251    const char *source;
252    struct {
253         int x, y, w, h;
254    } src, out;
255    Eina_Bool want : 1;
256    Eina_Bool download : 1;
257    Eina_Bool have : 1;
258    Ecore_File_Download_Job *job;
259    int try_num;
260 };
261
262 struct _Grid
263 {
264    Widget_Data *wd;
265    int tsize; // size of tile (tsize x tsize pixels)
266    int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
267    int iw, ih; // size of image in pixels
268    int w, h; // size of grid image in pixels (represented by grid)
269    int gw, gh; // size of grid in tiles
270    Eina_Matrixsparse *grid;
271 };
272
273 struct _Widget_Data
274 {
275    Evas_Object *obj;
276    Evas_Object *scr;
277    Evas_Object *pan_smart;
278    Evas_Object *rect;
279    Evas_Object *sep_maps_markers; //map objects are below this object and marker objects are on top
280    Pan *pan;
281    Evas_Coord pan_x, pan_y, minw, minh;
282
283    int id;
284    int zoom;
285    int zoom_method;
286    Elm_Map_Zoom_Mode mode;
287
288    Ecore_Job *calc_job;
289    Ecore_Timer *scr_timer;
290    Ecore_Timer *long_timer;
291    Ecore_Animator *zoom_animator;
292    double t;
293    struct {
294         int w, h;
295         int ow, oh, nw, nh;
296         struct {
297              double x, y;
298         } spos;
299    } size;
300    struct {
301         Eina_Bool show : 1;
302         Evas_Coord x, y ,w ,h;
303    } show;
304    int tsize;
305    int nosmooth;
306    Eina_List *grids;
307    Eina_Bool resized : 1;
308    Eina_Bool on_hold : 1;
309    Eina_Bool paused : 1;
310    Eina_Bool paused_markers : 1;
311
312    struct {
313         Eina_Bool enabled;
314         double lon, lat;
315    } center_on;
316
317    Ecore_Job *markers_place_job;
318    Eina_Matrixsparse **markers;
319    Eina_List *cells_displayed; // list of Eina_Matrixsparse_Cell
320    Evas_Coord markers_max_num;
321    int marker_max_w, marker_max_h;
322    int marker_zoom;
323    Eina_List *opened_bubbles; //opened bubbles, list of Map_Group *
324
325    Eina_List *groups_clas; // list of Elm_Map_Group_Class*
326    Eina_List *markers_clas; // list of Elm_Map_Markers_Class*
327
328    Elm_Map_Route_Sources route_source;
329    Eina_List *s_event_list;
330    int try_num;
331    int finish_num;
332
333    Eina_Hash *ua;
334    const char *user_agent;
335    Eina_List *route;
336    Eina_List *track;
337    Evas_Event_Mouse_Down ev;
338    Eina_List *names;
339    int multi_count;
340
341    struct {
342         Evas_Coord cx, cy;
343         double level, diff;
344         Eina_Bool doing : 1;
345    } pinch;
346
347    struct {
348         Evas_Coord cx, cy;
349         double a, d;
350         Eina_Bool doing : 1;
351    } rotate;
352
353    struct {
354         Evas_Coord cx, cy;
355         double level;
356    } pinch_zoom;
357    double wheel_zoom;
358    Ecore_Timer *wheel_timer;
359    Eina_Bool wheel_disabled : 1;
360
361    Eina_Array *modules;
362    Eina_List *map_sources_tab;
363    const char **source_names;
364    Evas_Map *map;
365    Ecore_Timer *zoom_timer;
366    Map_Sources_Tab *src;
367    const char *gpx_file;
368    int zoom_min, zoom_max;
369    Eina_List *download_list;
370    int download_num;
371 };
372
373 struct _Pan
374 {
375    Evas_Object_Smart_Clipped_Data __clipped_data;
376    Widget_Data *wd;
377 };
378
379 struct _Event
380 {
381    int device;
382
383    struct {
384         Evas_Coord x, y;
385    } start;
386
387    struct {
388         Evas_Coord x, y;
389    } prev;
390
391    Evas_Coord x, y, w, h;
392
393    Evas_Object *object;
394    Ecore_Timer *hold_timer;
395
396    int pinch_start_dis;
397    int pinch_dis;
398 };
399
400 struct _Route_Dump
401 {
402    int id;
403    char *fname;
404    double distance;
405    char *description;
406    char *coordinates;
407 };
408
409 enum _Route_Xml_Attribute
410 {
411    ROUTE_XML_NONE,
412    ROUTE_XML_DISTANCE,
413    ROUTE_XML_DESCRIPTION,
414    ROUTE_XML_COORDINATES,
415    ROUTE_XML_LAST
416 } Route_Xml_Attibute;
417
418 struct _Name_Dump
419 {
420    int id;
421    char *address;
422    double lon;
423    double lat;
424 };
425
426 enum _Name_Xml_Attribute
427 {
428    NAME_XML_NONE,
429    NAME_XML_NAME,
430    NAME_XML_LON,
431    NAME_XML_LAT,
432    NAME_XML_LAST
433 } Name_Xml_Attibute;
434
435 enum _Zoom_Method
436 {
437    ZOOM_METHOD_NONE,
438    ZOOM_METHOD_IN,
439    ZOOM_METHOD_OUT,
440    ZOOM_METHOD_LAST
441 } Zoom_Mode;
442
443 enum _Track_Xml_Attribute
444 {
445    TRACK_XML_NONE,
446    TRACK_XML_COORDINATES,
447    TRACK_XML_LAST
448 } Track_Xml_Attibute;
449
450
451 static const char *widtype = NULL;
452
453 static const char SIG_CHANGED[] = "changed";
454 static const char SIG_CLICKED[] = "clicked";
455 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
456 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
457 static const char SIG_LOAD_DETAIL[] = "load,detail";
458 static const char SIG_LONGPRESSED[] = "longpressed";
459 static const char SIG_PRESS[] = "press";
460 static const char SIG_SCROLL[] = "scroll";
461 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
462 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
463 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
464 static const char SIG_ZOOM_START[] = "zoom,start";
465 static const char SIG_ZOOM_STOP[] = "zoom,stop";
466 static const char SIG_DOWNLOADED[] = "downloaded";
467 static const char SIG_ROUTE_LOAD[] = "route,load";
468 static const char SIG_ROUTE_LOADED[] = "route,loaded";
469 static const char SIG_NAME_LOAD[] = "name,load";
470 static const char SIG_NAME_LOADED[] = "name,loaded";
471 static const Evas_Smart_Cb_Description _signals[] = {
472        {SIG_CHANGED, ""},
473        {SIG_CLICKED, ""},
474        {SIG_CLICKED_DOUBLE, ""},
475        {SIG_LOADED_DETAIL, ""},
476        {SIG_LOAD_DETAIL, ""},
477        {SIG_LONGPRESSED, ""},
478        {SIG_PRESS, ""},
479        {SIG_SCROLL, ""},
480        {SIG_SCROLL_DRAG_START, ""},
481        {SIG_SCROLL_DRAG_STOP, ""},
482        {SIG_ZOOM_CHANGE, ""},
483        {SIG_ZOOM_START, ""},
484        {SIG_ZOOM_STOP, ""},
485        {SIG_DOWNLOADED, ""},
486        {SIG_ROUTE_LOAD, ""},
487        {SIG_ROUTE_LOADED, ""},
488        {SIG_NAME_LOAD, ""},
489        {SIG_NAME_LOADED, ""},
490        {NULL, NULL}
491 };
492
493 static void _pan_calculate(Evas_Object *obj);
494
495 static Eina_Bool _hold_timer_cb(void *data);
496 static Eina_Bool _wheel_timer_cb(void *data);
497 static void _rect_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
498 static void _del_hook(Evas_Object *obj);
499 static void _theme_hook(Evas_Object *obj);
500 static void _on_focus_hook(void *data, Evas_Object *obj);
501 static void _sizing_eval(Evas_Object *obj);
502 static void _calc_job(void *data);
503 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
504                              Evas_Callback_Type type, void *event_info);
505 static void grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
506 static void grid_clear(Evas_Object *obj, Grid *g);
507 static Grid *grid_create(Evas_Object *obj);
508 static void grid_load(Evas_Object *obj, Grid *g);
509
510 static void _process_download_list(Evas_Object *obj);
511 static void _add_download_list(Evas_Object *obj, Grid_Item *gi);
512
513 static void _group_object_create(Marker_Group *group);
514 static void _group_object_free(Marker_Group *group);
515 static void _group_open_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
516 static void _group_bringin_cb(void *data, Evas_Object *obj, const char *emission, const char *soure);
517 static void _group_bubble_create(Marker_Group *group);
518 static void _group_bubble_free(Marker_Group *group);
519 static void _group_bubble_place(Marker_Group *group);
520
521 static int _group_bubble_content_update(Marker_Group *group);
522 static void _group_bubble_content_free(Marker_Group *group);
523 static void marker_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
524 static void _bubble_sc_hints_changed_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
525
526 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
527 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
528 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
529
530 static void _mouse_multi_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
531 static void _mouse_multi_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
532 static void _mouse_multi_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
533
534 static void route_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
535 static void track_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
536
537 static int
538 get_multi_device(Evas_Object *obj)
539 {
540    Widget_Data *wd = elm_widget_data_get(obj);
541    Eina_List *l;
542    Event *ev;
543
544    EINA_LIST_FOREACH(wd->s_event_list, l, ev)
545      {
546         if (ev->device) return ev->device;
547      }
548    return 0;
549 }
550
551 static Event *
552 create_event_object(void *data, Evas_Object *obj, int device)
553 {
554    Widget_Data *wd = elm_widget_data_get(data);
555    Event *ev = calloc(1, sizeof(Event));
556
557    EINA_SAFETY_ON_NULL_RETURN_VAL(ev, NULL);
558
559    ev->object = obj;
560    ev->device = device;
561    evas_object_geometry_get(obj, &ev->x, &ev->y, &ev->w, &ev->h);
562    wd->s_event_list = eina_list_append(wd->s_event_list, ev);
563    return ev;
564 }
565
566 static Event*
567 get_event_object(void *data, int device)
568 {
569    Widget_Data *wd = elm_widget_data_get(data);
570    Eina_List *l;
571    Event *ev;
572
573    EINA_LIST_FOREACH(wd->s_event_list, l, ev)
574      {
575         if (ev->device == device) break;
576         ev = NULL;
577      }
578    return ev;
579 }
580
581 static void
582 destroy_event_object(void *data, Event *ev)
583 {
584    Widget_Data *wd = elm_widget_data_get(data);
585    EINA_SAFETY_ON_NULL_RETURN(ev);
586    ev->pinch_dis = 0;
587    wd->s_event_list = eina_list_remove(wd->s_event_list, ev);
588    if (ev->hold_timer)
589      {
590         ecore_timer_del(ev->hold_timer);
591         ev->hold_timer = NULL;
592      }
593    free(ev);
594 }
595
596 static Eina_Bool
597 module_list_cb(Eina_Module *m, void *data)
598 {
599    ELM_CHECK_WIDTYPE(data, widtype) EINA_FALSE;
600    Widget_Data *wd = elm_widget_data_get(data);
601    Map_Sources_Tab *s;
602    ElmMapModuleSourceFunc source;
603    ElmMapModuleZoomMinFunc zoom_min;
604    ElmMapModuleZoomMaxFunc zoom_max;
605    ElmMapModuleUrlFunc url;
606    ElmMapModuleRouteSourceFunc route_source;
607    ElmMapModuleRouteUrlFunc route_url;
608    ElmMapModuleNameUrlFunc name_url;
609    ElmMapModuleGeoIntoCoordFunc geo_into_coord;
610    ElmMapModuleCoordIntoGeoFunc coord_into_geo;
611    const char *file;
612
613    if (!wd) return EINA_FALSE;
614
615    file = eina_module_file_get(m);
616    if (!eina_module_load(m))
617      {
618         ERR("could not load module \"%s\": %s", file, eina_error_msg_get(eina_error_get()));
619         return EINA_FALSE;
620      }
621
622    source = eina_module_symbol_get(m, "map_module_source_get");
623    zoom_min = eina_module_symbol_get(m, "map_module_zoom_min_get");
624    zoom_max = eina_module_symbol_get(m, "map_module_zoom_max_get");
625    url = eina_module_symbol_get(m, "map_module_url_get");
626    route_source = eina_module_symbol_get(m, "map_module_route_source_get");
627    route_url = eina_module_symbol_get(m, "map_module_route_url_get");
628    name_url = eina_module_symbol_get(m, "map_module_name_url_get");
629    geo_into_coord = eina_module_symbol_get(m, "map_module_geo_into_coord");
630    coord_into_geo = eina_module_symbol_get(m, "map_module_coord_into_geo");
631    if ((!source) || (!zoom_min) || (!zoom_max) || (!url) || (!route_source) || (!route_url) || (!name_url) || (!geo_into_coord) || (!coord_into_geo))
632      {
633         ERR("could not find map_module_source_get() in module \"%s\": %s", file, eina_error_msg_get(eina_error_get()));
634         eina_module_unload(m);
635         return EINA_FALSE;
636      }
637    s = calloc(1, sizeof(Map_Sources_Tab));
638    EINA_SAFETY_ON_NULL_RETURN_VAL(s, EINA_FALSE);
639    s->name = source();
640    s->zoom_min = zoom_min();
641    s->zoom_max = zoom_max();
642    s->url_cb = url;
643    s->route_source = route_source();
644    s->route_url_cb = route_url;
645    s->name_url_cb = name_url;
646    s->geo_into_coord = geo_into_coord;
647    s->coord_into_geo = coord_into_geo;
648    wd->map_sources_tab = eina_list_append(wd->map_sources_tab, s);
649
650    return EINA_TRUE;
651 }
652
653 static void
654 module_init(void *data)
655 {
656    ELM_CHECK_WIDTYPE(data, widtype);
657    Widget_Data *wd = elm_widget_data_get(data);
658
659    if (!wd) return;
660    wd->modules = eina_module_list_get(wd->modules, MODULES_PATH, 1, &module_list_cb, data);
661 }
662
663 static void
664 source_init(void *data)
665 {
666    ELM_CHECK_WIDTYPE(data, widtype);
667    Widget_Data *wd = elm_widget_data_get(data);
668    Map_Sources_Tab *s;
669    Eina_List *l;
670    int idx;
671
672    if (!wd) return;
673    for (idx = 0; idx < 4; idx++)
674      {
675         s = calloc(1, sizeof(Map_Sources_Tab));
676         EINA_SAFETY_ON_NULL_RETURN(s);
677         s->name = default_map_sources_tab[idx].name;
678         s->zoom_min = default_map_sources_tab[idx].zoom_min;
679         s->zoom_max = default_map_sources_tab[idx].zoom_max;
680         s->url_cb = default_map_sources_tab[idx].url_cb;
681         s->route_source = default_map_sources_tab[idx].route_source;
682         s->route_url_cb = default_map_sources_tab[idx].route_url_cb;
683         s->name_url_cb = default_map_sources_tab[idx].name_url_cb;
684         s->geo_into_coord = default_map_sources_tab[idx].geo_into_coord;
685         s->coord_into_geo = default_map_sources_tab[idx].coord_into_geo;
686         wd->map_sources_tab = eina_list_append(wd->map_sources_tab, s);
687         if (!idx) wd->src = s;
688      }
689    module_init(data);
690
691    int n = eina_list_count(wd->map_sources_tab);
692    wd->source_names = malloc(sizeof(char *) * (n + 1));
693    if (!wd->source_names)
694      {
695         ERR("init source names failed.");
696         return;
697      }
698    idx = 0;
699    EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
700      {
701         wd->source_names[idx] = strdup(s->name);
702         INF("source : %s", wd->source_names[idx]);
703         idx++;
704      }
705    wd->source_names[idx] = NULL;
706 }
707
708 static void
709 zoom_min_get(void *data)
710 {
711    ELM_CHECK_WIDTYPE(data, widtype);
712    Widget_Data *wd = elm_widget_data_get(data);
713    Map_Sources_Tab *s;
714    Eina_List *l;
715    int tz;
716
717    if (!wd) return;
718    EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
719      {
720         tz = s->zoom_min;
721         if (tz < wd->zoom_min) wd->zoom_min = tz;
722      }
723 }
724
725 static void
726 zoom_max_get(void *data)
727 {
728    ELM_CHECK_WIDTYPE(data, widtype);
729    Widget_Data *wd = elm_widget_data_get(data);
730    Map_Sources_Tab *s;
731    Eina_List *l;
732    int tz;
733
734    if (!wd) return;
735    EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
736      {
737         tz = s->zoom_max;
738         if (tz > wd->zoom_max) wd->zoom_max = tz;
739      }
740 }
741
742 static void
743 obj_rotate_zoom(void *data, Evas_Object *obj)
744 {
745    ELM_CHECK_WIDTYPE(data, widtype);
746    Widget_Data *wd = elm_widget_data_get(data);
747    int ow, oh, iw, ih;
748    if ((!wd->pinch.cx) && (!wd->pinch.cy))
749      {
750         wd->pinch.cx = wd->rotate.cx;
751         wd->pinch.cy = wd->rotate.cy;
752      }
753
754    evas_map_util_points_populate_from_object_full(wd->map, obj, 0);
755    evas_object_image_size_get(obj, &iw, &ih);
756    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
757    if ((ow < iw) || (oh < ih))
758      {
759         ow *= (double)iw / ow;
760         oh *= (double)ih / oh;
761         evas_map_point_image_uv_set(wd->map, 1, ow, 0);
762         evas_map_point_image_uv_set(wd->map, 2, ow, oh);
763         evas_map_point_image_uv_set(wd->map, 3, 0, oh);
764      }
765    evas_map_util_zoom(wd->map, wd->pinch.level, wd->pinch.level, wd->pinch.cx, wd->pinch.cy);
766    evas_map_util_rotate(wd->map, wd->rotate.d, wd->rotate.cx, wd->rotate.cy);
767    evas_object_map_enable_set(obj, EINA_TRUE);
768    evas_object_map_set(obj, wd->map);
769 }
770
771 static void
772 #ifdef ELM_EMAP
773 track_place(Evas_Object *obj, Grid *g __UNUSED__, Evas_Coord px, Evas_Coord py, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow, Evas_Coord oh)
774 #else
775 track_place(Evas_Object *obj __UNUSED__, Grid *g __UNUSED__, Evas_Coord px __UNUSED__, Evas_Coord py __UNUSED__, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow __UNUSED__, Evas_Coord oh __UNUSED__)
776 #endif
777 {
778 #ifdef ELM_EMAP
779    ELM_CHECK_WIDTYPE(obj, widtype);
780    Widget_Data *wd = elm_widget_data_get(obj);
781    Eina_List *l;
782    Evas_Object *route;
783    int xmin, xmax, ymin, ymax;
784
785    if (!wd) return;
786    Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
787
788    EINA_LIST_FOREACH(wd->track, l, route)
789      {
790         elm_map_utils_convert_geo_into_coord(wd->obj, elm_route_lon_min_get(route), elm_route_lat_max_get(route), size, &xmin, &ymin);
791         elm_map_utils_convert_geo_into_coord(wd->obj, elm_route_lon_max_get(route), elm_route_lat_min_get(route), size, &xmax, &ymax);
792
793         if( !(xmin < px && xmax < px) && !(xmin > px+ow && xmax > px+ow))
794         {
795            if( !(ymin < py && ymax < py) && !(ymin > py+oh && ymax > py+oh))
796            {
797               //display the route
798               evas_object_move(route, xmin - px + ox, ymin - py + oy);
799               evas_object_resize(route, xmax - xmin, ymax - ymin);
800
801               evas_object_raise(route);
802               obj_rotate_zoom(obj, route);
803               evas_object_show(route);
804
805               continue;
806            }
807         }
808         //the route is not display
809         evas_object_hide(route);
810      }
811 #endif
812 }
813 static void
814 route_place(Evas_Object *obj, Grid *g __UNUSED__, Evas_Coord px, Evas_Coord py, Evas_Coord ox __UNUSED__, Evas_Coord oy __UNUSED__, Evas_Coord ow, Evas_Coord oh)
815 {
816    ELM_CHECK_WIDTYPE(obj, widtype);
817    Widget_Data *wd = elm_widget_data_get(obj);
818    Eina_List *lr, *lp, *ln;
819    Path_Node *n;
820    Evas_Object *p;
821    Elm_Map_Route *r;
822    int nodes;
823    int x, y, rx, ry;
824    double a;
825
826    if (!wd) return;
827    Evas_Coord size = pow(2.0, wd->zoom)*wd->tsize;
828
829    EINA_LIST_FOREACH(wd->route, lr, r)
830      {
831         EINA_LIST_FOREACH(r->path, lp, p)
832           {
833              evas_object_polygon_points_clear(p);
834           }
835
836         evas_object_geometry_get(wd->rect, &rx, &ry, NULL, NULL);
837         nodes = eina_list_count(r->nodes);
838
839         EINA_LIST_FOREACH(r->nodes, ln, n)
840           {
841              if ((!wd->zoom) || ((n->idx) &&
842                  ((n->idx % (int)ceil((double)nodes/(double)size*100.0))))) continue;
843              if (r->inbound)
844                {
845                   elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
846                   if ((x >= px - ow) && (x <= (px + ow*2)) &&
847                       (y >= py - oh) && (y <= (py + oh*2)))
848                     {
849                        x = x - px + rx;
850                        y = y - py + ry;
851
852                        p = eina_list_nth(r->path, n->idx);
853                        a = (double)(y - r->y) / (double)(x - r->x);
854                        if ((abs(a) >= 1) || (r->x == x))
855                          {
856                             evas_object_polygon_point_add(p, r->x - 3, r->y);
857                             evas_object_polygon_point_add(p, r->x + 3, r->y);
858                             evas_object_polygon_point_add(p, x + 3, y);
859                             evas_object_polygon_point_add(p, x - 3, y);
860                          }
861                        else
862                          {
863                             evas_object_polygon_point_add(p, r->x, r->y - 3);
864                             evas_object_polygon_point_add(p, r->x, r->y + 3);
865                             evas_object_polygon_point_add(p, x, y + 3);
866                             evas_object_polygon_point_add(p, x, y - 3);
867                          }
868
869                        evas_object_color_set(p, r->color.r, r->color.g, r->color.b, r->color.a);
870                        evas_object_raise(p);
871                        obj_rotate_zoom(obj, p);
872                        evas_object_show(p);
873                        r->x = x;
874                        r->y = y;
875                     }
876                   else r->inbound = EINA_FALSE;
877                }
878              else
879                {
880                   elm_map_utils_convert_geo_into_coord(wd->obj, n->pos.lon, n->pos.lat, size, &x, &y);
881                   if ((x >= px - ow) && (x <= (px + ow*2)) &&
882                       (y >= py - oh) && (y <= (py + oh*2)))
883                     {
884                        r->x = x - px + rx;
885                        r->y = y - py + ry;
886                        r->inbound = EINA_TRUE;
887                     }
888                   else r->inbound = EINA_FALSE;
889                }
890           }
891           r->inbound = EINA_FALSE;
892      }
893 }
894
895 static void
896 rect_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
897 {
898    ELM_CHECK_WIDTYPE(obj, widtype);
899    Widget_Data *wd = elm_widget_data_get(obj);
900    Evas_Coord ax, ay, gw, gh, hh, ww;
901
902    if (!wd) return;
903    evas_object_geometry_get(wd->rect, NULL, NULL, &ww, &hh);
904
905    ax = 0;
906    ay = 0;
907    gw = wd->size.w;
908    gh = wd->size.h;
909
910    if ((ww == gw) && (hh == gh)) return;
911
912    if (ow > gw) ax = (ow - gw) / 2;
913    if (oh > gh) ay = (oh - gh) / 2;
914    evas_object_move(wd->rect,
915                     ox + 0 - px + ax,
916                     oy + 0 - py + ay);
917    evas_object_resize(wd->rect, gw, gh);
918
919    if (wd->show.show)
920      {
921         wd->show.show = EINA_FALSE;
922         elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
923      }
924 }
925
926 static void
927 marker_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
928 {
929    ELM_CHECK_WIDTYPE(obj, widtype);
930    Widget_Data *wd = elm_widget_data_get(obj);
931    Evas_Coord ax, ay, gw, gh, tx, ty;
932    Eina_List *l, *markers;
933    Eina_Matrixsparse_Cell *cell;
934    Marker_Group *group;
935    int xx, yy, ww, hh;
936    char buf[PATH_MAX];
937    int y, x;
938    int g_xx, g_yy, g_hh, g_ww;
939
940    if (!wd) return;
941    if (g != eina_list_data_get(wd->grids)) return;
942
943    ax = 0;
944    ay = 0;
945    gw = wd->size.w;
946    gh = wd->size.h;
947    if (ow > gw) ax = (ow - gw) / 2;
948    if (oh > gh) ay = (oh - gh) / 2;
949
950    if (wd->zoom != wd->marker_zoom)
951      {
952         EINA_LIST_FREE(wd->cells_displayed, cell)
953           {
954              EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
955                {
956                   if (group->obj) _group_object_free(group);
957                }
958           }
959      }
960    wd->marker_zoom = wd->zoom;
961
962    if ((wd->paused_markers)
963        && ((wd->size.nw != wd->size.w) || (wd->size.nh != wd->size.h)) )
964      return;
965
966    g_xx = wd->pan_x / wd->tsize;
967    if (g_xx < 0) g_xx = 0;
968    g_yy = wd->pan_y / wd->tsize;
969    if (g_yy < 0) g_yy = 0;
970    g_ww = (ow / wd->tsize) + 1;
971    if (g_xx + g_ww >= g->gw) g_ww = g->gw - g_xx - 1;
972    g_hh = (oh / wd->tsize) + 1;
973    if (g_yy + g_hh >= g->gh) g_hh = g->gh - g_yy - 1;
974
975    //hide groups no more displayed
976    EINA_LIST_FREE(wd->cells_displayed, cell)
977      {
978         eina_matrixsparse_cell_position_get(cell, (unsigned long *)&y, (unsigned long *)&x);
979         if ((y < g_yy) || (y > g_yy + g_hh) || (x < g_xx) || (x > g_xx + g_ww))
980           {
981              EINA_LIST_FOREACH(eina_matrixsparse_cell_data_get(cell), l, group)
982                {
983                   if (group->obj) _group_object_free(group);
984                }
985           }
986      }
987
988    if (!wd->marker_zoom)
989      {
990         g_ww = 0;
991         g_hh = 0;
992      }
993
994    for (y = g_yy; y <= g_yy + g_hh; y++)
995      {
996         for (x = g_xx; x <= g_xx + g_ww; x++)
997           {
998              if (!wd->markers[wd->zoom]) continue;
999              eina_matrixsparse_cell_idx_get(wd->markers[wd->zoom], y, x, &cell);
1000              if (!cell) continue;
1001              wd->cells_displayed = eina_list_append(wd->cells_displayed, cell);
1002              markers = eina_matrixsparse_cell_data_get(cell);
1003              EINA_LIST_FOREACH(markers, l, group)
1004                {
1005                   if (!group->markers) continue;
1006                   if (group->clas->zoom_displayed > wd->zoom) continue;
1007
1008                   xx = group->x;
1009                   yy = group->y;
1010                   ww = group->w;
1011                   hh = group->h;
1012
1013                   if (eina_list_count(group->markers) == 1)
1014                     {
1015                        Elm_Map_Marker *m = eina_list_data_get(group->markers);
1016                        ww = m->clas->priv.edje_w;
1017                        hh = m->clas->priv.edje_h;
1018                     }
1019
1020                   if (ww <= 0) ww = 1;
1021                   if (hh <= 0) hh = 1;
1022
1023                   if ((gw != g->w) && (g->w > 0))
1024                     {
1025                        tx = xx;
1026                        xx = ((long long )gw * xx) / g->w;
1027                        ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1028                     }
1029                   if ((gh != g->h) && (g->h > 0))
1030                     {
1031                        ty = yy;
1032                        yy = ((long long)gh * yy) / g->h;
1033                        hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1034                     }
1035
1036                   if ((!group->clas->hide)
1037                       && (xx-px+ax+ox >= ox) && (xx-px+ax+ox<= ox+ow)
1038                       && (yy-py+ay+oy >= oy) && (yy-py+ay+oy<= oy+oh))
1039                     {
1040                        if (!group->obj) _group_object_create(group);
1041
1042                        if (group->update_nbelems)
1043                          {
1044                             group->update_nbelems = EINA_FALSE;
1045                             if (eina_list_count(group->markers) > 1)
1046                               {
1047                                  snprintf(buf, sizeof(buf), "%d", eina_list_count(group->markers));
1048                                  edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", buf);
1049                               }
1050                             else
1051                               edje_object_part_text_set(elm_layout_edje_get(group->obj), "elm.text", "");
1052                          }
1053                        evas_object_move(group->obj,
1054                                         xx - px + ax + ox - ww/2,
1055                                         yy - py + ay + oy - hh/2);
1056                        if ((!wd->paused_markers) || (group->update_resize))
1057                          {
1058                             group->update_resize = EINA_FALSE;
1059                             evas_object_resize(group->obj, ww, hh);
1060                             obj_rotate_zoom(obj, group->obj);
1061                          }
1062                        if (group->update_raise)
1063                          {
1064                             group->update_raise = EINA_FALSE;
1065                             evas_object_raise(group->obj);
1066                             obj_rotate_zoom(obj, group->obj);
1067                             evas_object_show(group->obj);
1068                          }
1069                        if (group->bubble) _group_bubble_place(group);
1070                     }
1071                   else if (group->obj)
1072                     {
1073                        _group_object_free(group);
1074                     }
1075                }
1076           }
1077      }
1078 }
1079
1080 static void
1081 grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
1082 {
1083    ELM_CHECK_WIDTYPE(obj, widtype);
1084    Widget_Data *wd = elm_widget_data_get(obj);
1085    Evas_Coord ax, ay, gw, gh, tx, ty;
1086    int xx, yy, ww, hh;
1087
1088    if (!wd) return;
1089    ax = 0;
1090    ay = 0;
1091    gw = wd->size.w;
1092    gh = wd->size.h;
1093    if (ow > gw) ax = (ow - gw) / 2;
1094    if (oh > gh) ay = (oh - gh) / 2;
1095
1096    Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1097    Eina_Matrixsparse_Cell *cell;
1098
1099    EINA_ITERATOR_FOREACH(it, cell)
1100      {
1101         Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1102
1103         xx = gi->out.x;
1104         yy = gi->out.y;
1105         ww = gi->out.w;
1106         hh = gi->out.h;
1107         if ((gw != g->w) && (g->w > 0))
1108           {
1109              tx = xx;
1110              xx = ((long long )gw * xx) / g->w;
1111              ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1112           }
1113         if ((gh != g->h) && (g->h > 0))
1114           {
1115              ty = yy;
1116              yy = ((long long)gh * yy) / g->h;
1117              hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1118           }
1119         evas_object_move(gi->img,
1120                          xx - px + ax + ox,
1121                          yy - py + ay + oy);
1122
1123         evas_object_resize(gi->img, ww, hh);
1124
1125         obj_rotate_zoom(obj, gi->img);
1126         /*evas_object_move(gi->txt,
1127                            xx - px + ax + ox,
1128                            yy - py + ay + oy);
1129
1130           evas_object_resize(gi->txt, ww, hh);
1131          */
1132      }
1133    eina_iterator_free(it);
1134 }
1135
1136 static void
1137 grid_clear(Evas_Object *obj, Grid *g)
1138 {
1139    ELM_CHECK_WIDTYPE(obj, widtype);
1140    Widget_Data *wd = elm_widget_data_get(obj);
1141    char buf[PATH_MAX];
1142
1143    if (!wd) return;
1144    if (!g->grid) return;
1145
1146    Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1147    Eina_Matrixsparse_Cell *cell;
1148
1149    snprintf(buf, sizeof(buf), DEST_DIR_ZOOM_PATH, wd->id, g->zoom);
1150    ecore_file_recursive_rm(buf);
1151
1152    EINA_ITERATOR_FOREACH(it, cell)
1153      {
1154         Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1155         evas_object_del(gi->img);
1156         //evas_object_del(gi->txt);
1157
1158         wd->download_list = eina_list_remove(wd->download_list, gi);
1159         gi->want = EINA_FALSE;
1160
1161         if (gi->job)
1162           {
1163              DBG("DOWNLOAD abort %s", gi->file);
1164              ecore_file_download_abort(gi->job);
1165              ecore_file_remove(gi->file);
1166              gi->have = EINA_FALSE;
1167              gi->job = NULL;
1168              wd->try_num--;
1169           }
1170         if (gi->file)
1171           eina_stringshare_del(gi->file);
1172         if (gi->source)
1173           eina_stringshare_del(gi->source);
1174
1175         free(gi);
1176      }
1177    eina_matrixsparse_free(g->grid);
1178    eina_iterator_free(it);
1179    g->grid = NULL;
1180    g->gw = 0;
1181    g->gh = 0;
1182 }
1183
1184 static void
1185 _tile_update(Grid_Item *gi)
1186 {
1187    gi->want = EINA_FALSE;
1188    gi->download = EINA_FALSE;
1189    evas_object_image_file_set(gi->img, gi->file, NULL);
1190    if (evas_object_image_load_error_get(gi->img) != EVAS_LOAD_ERROR_NONE)
1191      {
1192         ERR("Image loading error (%s)", gi->file);
1193         ecore_file_remove(gi->file);
1194         gi->have = EINA_FALSE;
1195         return;
1196      }
1197
1198    obj_rotate_zoom(gi->wd->obj, gi->img);
1199    evas_object_show(gi->img);
1200
1201    //evas_object_text_text_set(gi->txt, gi->file);
1202    //evas_object_show(gi->txt);
1203
1204    gi->have = EINA_TRUE;
1205 }
1206
1207 static void
1208 _tile_downloaded(void *data, const char *file __UNUSED__, int status)
1209 {
1210    Grid_Item *gi = data;
1211
1212    gi->wd->download_num--;
1213    gi->download = EINA_FALSE;
1214    gi->job = NULL;
1215
1216    if ((gi->want) && (status == 200))
1217      {
1218         _tile_update(gi);
1219         DBG("DOWNLOAD done %s", gi->file);
1220      }
1221
1222    if (status != 200)
1223      {
1224         DBG("Download failed %s (%d) ", gi->file, status);
1225         ecore_file_remove(gi->file);
1226         gi->have = EINA_FALSE;
1227      }
1228    else
1229      gi->wd->finish_num++;
1230
1231    evas_object_smart_callback_call(gi->wd->obj, SIG_DOWNLOADED, NULL);
1232    if (!gi->wd->download_num)
1233      {
1234         edje_object_signal_emit(elm_smart_scroller_edje_object_get(gi->wd->scr), "elm,state,busy,stop", "elm");
1235         evas_object_smart_callback_call(gi->wd->obj, SIG_LOADED_DETAIL, NULL);
1236      }
1237    _process_download_list(gi->wd->obj);
1238 }
1239
1240 static void
1241 _process_download_list(Evas_Object *obj)
1242 {
1243    ELM_CHECK_WIDTYPE(obj, widtype);
1244    Widget_Data *wd = elm_widget_data_get(obj);
1245    Eina_List *l, *ll;
1246    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, tx, ty, gw, gh, xx, yy, ww, hh;
1247    Grid_Item *gi;
1248
1249    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
1250    evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
1251
1252    gw = wd->size.w;
1253    gh = wd->size.h;
1254
1255    EINA_LIST_FOREACH_SAFE(wd->download_list, l, ll, gi)
1256      {
1257         xx = gi->out.x;
1258         yy = gi->out.y;
1259         ww = gi->out.w;
1260         hh = gi->out.h;
1261
1262         if ((gw != gi->g->w) && (gi->g->w > 0))
1263           {
1264              tx = xx;
1265              xx = ((long long )gw * xx) / gi->g->w;
1266              ww = (((long long)gw * (tx + ww)) / gi->g->w) - xx;
1267           }
1268         if ((gh != gi->g->h) && (gi->g->h > 0))
1269           {
1270              ty = yy;
1271              yy = ((long long)gh * yy) / gi->g->h;
1272              hh = (((long long)gh * (ty + hh)) / gi->g->h) - yy;
1273           }
1274         if (!ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
1275                                  yy  - wd->pan_y + oy,
1276                                  ww, hh,
1277                                  cvx, cvy, cvw, cvh))
1278           {
1279              gi->download = EINA_FALSE;
1280              wd->download_list = eina_list_remove(wd->download_list, gi);
1281           }
1282      }
1283
1284    EINA_LIST_REVERSE_FOREACH_SAFE(wd->download_list, l, ll, gi)
1285      {
1286         if (gi->wd->download_num >= MAX_CONCURRENT_DOWNLOAD)
1287           break;
1288
1289         Eina_Bool ret = ecore_file_download_full(gi->source, gi->file, _tile_downloaded, NULL, gi, &(gi->job), wd->ua);
1290         if (!ret || !gi->job)
1291           WRN("Can't start to download %s to %s", gi->source, gi->file);
1292         else
1293           {
1294              gi->wd->download_num++;
1295              wd->try_num++;
1296              wd->download_list = eina_list_remove(wd->download_list, gi);
1297              if (wd->download_num == 1)
1298                edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,state,busy,start", "elm");
1299           }
1300      }
1301 }
1302
1303 static void
1304 _add_download_list(Evas_Object *obj, Grid_Item *gi)
1305 {
1306    ELM_CHECK_WIDTYPE(obj, widtype);
1307    Widget_Data *wd = elm_widget_data_get(obj);
1308
1309    wd->download_list = eina_list_remove(wd->download_list, gi);
1310    wd->download_list = eina_list_append(wd->download_list, gi);
1311    _process_download_list(obj);
1312 }
1313
1314 static Grid *
1315 grid_create(Evas_Object *obj)
1316 {
1317    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1318    Widget_Data *wd = elm_widget_data_get(obj);
1319    Grid *g;
1320
1321    if ((!wd) || (!wd->src)) return NULL;
1322    g = calloc(1, sizeof(Grid));
1323
1324    g->zoom = wd->zoom;
1325    g->tsize = wd->tsize;
1326    g->wd = wd;
1327
1328    if (g->zoom > wd->src->zoom_max) return NULL;
1329    if (g->zoom < wd->src->zoom_min) return NULL;
1330
1331    int size =  pow(2.0, wd->zoom);
1332    g->gw = size;
1333    g->gh = size;
1334
1335    g->w = g->tsize * g->gw;
1336    g->h = g->tsize * g->gh;
1337
1338    g->grid = eina_matrixsparse_new(g->gh, g->gw, NULL, NULL);
1339
1340    return g;
1341 }
1342
1343 static void
1344 grid_load(Evas_Object *obj, Grid *g)
1345 {
1346    ELM_CHECK_WIDTYPE(obj, widtype);
1347    Widget_Data *wd = elm_widget_data_get(obj);
1348    int x, y;
1349    int size;
1350    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, tx, ty, gw, gh, xx, yy, ww, hh;
1351    Eina_Iterator *it;
1352    Eina_Matrixsparse_Cell *cell;
1353    Grid_Item *gi;
1354
1355    if ((!wd) || (!wd->src)) return;
1356    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
1357    evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
1358
1359    gw = wd->size.w;
1360    gh = wd->size.h;
1361
1362    if ((gw <= 0) || (gh <= 0)) return;
1363
1364    size = g->tsize;
1365    if ((gw != g->w) && (g->w > 0))
1366      size = ((long long)gw * size) / g->w;
1367    if (size < (g->tsize / 2)) return; // else we will load to much tiles
1368
1369    it = eina_matrixsparse_iterator_new(g->grid);
1370
1371    EINA_ITERATOR_FOREACH(it, cell)
1372      {
1373         gi = eina_matrixsparse_cell_data_get(cell);
1374
1375         xx = gi->out.x;
1376         yy = gi->out.y;
1377         ww = gi->out.w;
1378         hh = gi->out.h;
1379
1380         if ((gw != g->w) && (g->w > 0))
1381           {
1382              tx = xx;
1383              xx = ((long long )gw * xx) / g->w;
1384              ww = (((long long)gw * (tx + ww)) / g->w) - xx;
1385           }
1386         if ((gh != g->h) && (g->h > 0))
1387           {
1388              ty = yy;
1389              yy = ((long long)gh * yy) / g->h;
1390              hh = (((long long)gh * (ty + hh)) / g->h) - yy;
1391           }
1392
1393         if (!ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
1394                                  yy  - wd->pan_y + oy,
1395                                  ww, hh,
1396                                  cvx, cvy, cvw, cvh))
1397           {
1398              if (gi->want)
1399                {
1400                   evas_object_hide(gi->img);
1401                   //evas_object_hide(gi->txt);
1402                   evas_object_image_file_set(gi->img, NULL, NULL);
1403                   gi->want = EINA_FALSE;
1404                   gi->have = EINA_FALSE;
1405
1406                   if (gi->job)
1407                     {
1408                        DBG("DOWNLOAD abort %s", gi->file);
1409                        ecore_file_download_abort(gi->job);
1410                        ecore_file_remove(gi->file);
1411                        gi->job = NULL;
1412                        wd->try_num--;
1413                     }
1414                   gi->download = EINA_FALSE;
1415                }
1416              else if (gi->have)
1417                {
1418                   evas_object_hide(gi->img);
1419                   //evas_object_hide(gi->txt);
1420                   evas_object_image_preload(gi->img, 1);
1421                   evas_object_image_file_set(gi->img, NULL, NULL);
1422                   gi->have = EINA_FALSE;
1423                   gi->want = EINA_FALSE;
1424                }
1425           }
1426      }
1427    eina_iterator_free(it);
1428
1429    xx = wd->pan_x / size - 1;
1430    if (xx < 0) xx = 0;
1431
1432    yy = wd->pan_y / size - 1;
1433    if (yy < 0) yy = 0;
1434
1435    ww = ow / size + 2;
1436    if (xx + ww >= g->gw) ww = g->gw - xx - 1;
1437
1438    hh = oh / size + 2;
1439    if (yy + hh >= g->gh) hh = g->gh - yy - 1;
1440
1441    for (y = yy; y <= yy + hh; y++)
1442      {
1443         for (x = xx; x <= xx + ww; x++)
1444           {
1445              gi = eina_matrixsparse_data_idx_get(g->grid, y, x);
1446
1447              if ((!gi) && (g != eina_list_data_get(wd->grids)))
1448                continue;
1449
1450              if (!gi)
1451                {
1452                   gi = calloc(1, sizeof(Grid_Item));
1453                   gi->src.x = x * g->tsize;
1454                   gi->src.y = y * g->tsize;
1455                   gi->src.w = g->tsize;
1456                   gi->src.h = g->tsize;
1457
1458                   gi->out.x = gi->src.x;
1459                   gi->out.y = gi->src.y;
1460                   gi->out.w = gi->src.w;
1461                   gi->out.h = gi->src.h;
1462
1463                   gi->wd = wd;
1464                   gi->g = g;
1465
1466                   gi->img = evas_object_image_add(evas_object_evas_get(obj));
1467                   evas_object_image_scale_hint_set
1468                      (gi->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1469                   evas_object_image_filled_set(gi->img, 1);
1470
1471                   evas_object_smart_member_add(gi->img, wd->pan_smart);
1472                   elm_widget_sub_object_add(obj, gi->img);
1473                   evas_object_pass_events_set(gi->img, EINA_TRUE);
1474                   evas_object_stack_below(gi->img, wd->sep_maps_markers);
1475
1476 /*                gi->txt = evas_object_text_add(evas_object_evas_get(obj));
1477                   evas_object_text_font_set(gi->txt, "Vera", 12);
1478                   evas_object_color_set(gi->txt, 100, 100, 100, 255);
1479                   evas_object_smart_member_add(gi->txt,
1480                                                wd->pan_smart);
1481                   elm_widget_sub_object_add(obj, gi->txt);
1482                   evas_object_pass_events_set(gi->txt, EINA_TRUE);
1483 */
1484                   eina_matrixsparse_data_idx_set(g->grid, y, x, gi);
1485                }
1486
1487              if ((!gi->have) && (!gi->download))
1488                {
1489                   char buf[PATH_MAX], buf2[PATH_MAX];
1490                   char *source;
1491
1492                   gi->want = EINA_TRUE;
1493
1494                   snprintf(buf, sizeof(buf), DEST_DIR_PATH, wd->id, g->zoom, x);
1495                   if (!ecore_file_exists(buf))
1496                     ecore_file_mkpath(buf);
1497
1498                   snprintf(buf2, sizeof(buf2), DEST_FILE_PATH, buf, y);
1499
1500                   source = wd->src->url_cb(obj, x, y, g->zoom);
1501                   if ((!source) || (strlen(source)==0)) continue;
1502
1503                   eina_stringshare_replace(&gi->file, buf2);
1504                   eina_stringshare_replace(&gi->source, source);
1505
1506                   if ((ecore_file_exists(buf2)) || (g == eina_list_data_get(wd->grids)))
1507                     {
1508                        gi->download = EINA_TRUE;
1509                        if (ecore_file_exists(buf2))
1510                          _tile_update(gi);
1511                        else
1512                          _add_download_list(obj, gi);
1513                     }
1514                   if (source) free(source);
1515                }
1516              else if (gi->have)
1517                {
1518                   obj_rotate_zoom(obj, gi->img);
1519                   evas_object_show(gi->img);
1520                }
1521           }
1522      }
1523 }
1524
1525 static void
1526 grid_clearall(Evas_Object *obj)
1527 {
1528    ELM_CHECK_WIDTYPE(obj, widtype);
1529    Widget_Data *wd = elm_widget_data_get(obj);
1530    Grid *g;
1531
1532    if (!wd) return;
1533    EINA_LIST_FREE(wd->grids, g)
1534      {
1535         grid_clear(obj, g);
1536         free(g);
1537      }
1538    wd->download_list = eina_list_free(wd->download_list);
1539 }
1540
1541 static void
1542 _smooth_update(Evas_Object *obj)
1543 {
1544    ELM_CHECK_WIDTYPE(obj, widtype);
1545    Widget_Data *wd = elm_widget_data_get(obj);
1546    Eina_List *l;
1547    Grid *g;
1548
1549    if (!wd) return;
1550    EINA_LIST_FOREACH(wd->grids, l, g)
1551      {
1552         Eina_Iterator *it = eina_matrixsparse_iterator_new(g->grid);
1553         Eina_Matrixsparse_Cell *cell;
1554
1555         EINA_ITERATOR_FOREACH(it, cell)
1556           {
1557              Grid_Item *gi = eina_matrixsparse_cell_data_get(cell);
1558              evas_object_image_smooth_scale_set(gi->img, (!wd->nosmooth));
1559           }
1560         eina_iterator_free(it);
1561      }
1562 }
1563
1564 static Eina_Bool
1565 _scr_timeout(void *data)
1566 {
1567    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1568    Widget_Data *wd = elm_widget_data_get(data);
1569
1570    if (!wd) return ECORE_CALLBACK_CANCEL;
1571    wd->nosmooth--;
1572    if (!wd->nosmooth) _smooth_update(data);
1573    wd->scr_timer = NULL;
1574    return ECORE_CALLBACK_CANCEL;
1575 }
1576
1577 static void
1578 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1579 {
1580    ELM_CHECK_WIDTYPE(data, widtype);
1581    Widget_Data *wd = elm_widget_data_get(data);
1582
1583    if (!wd) return;
1584    if (!wd->scr_timer)
1585      {
1586         wd->nosmooth++;
1587         if (wd->nosmooth == 1) _smooth_update(data);
1588      }
1589    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
1590    wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
1591 }
1592
1593 static void
1594 zoom_do(Evas_Object *obj)
1595 {
1596    ELM_CHECK_WIDTYPE(obj, widtype);
1597    Widget_Data *wd = elm_widget_data_get(obj);
1598    Evas_Coord xx, yy, ow, oh;
1599
1600    if (!wd) return;
1601    wd->size.w = wd->size.nw;
1602    wd->size.h = wd->size.nh;
1603
1604    elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
1605
1606    if (wd->center_on.enabled)
1607      {
1608         elm_map_utils_convert_geo_into_coord(obj, wd->center_on.lon, wd->center_on.lat, wd->size.w, &xx, &yy);
1609         xx -= ow / 2;
1610         yy -= oh / 2;
1611      }
1612    else
1613      {
1614         xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
1615         yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
1616      }
1617
1618
1619    if (xx < 0) xx = 0;
1620    else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
1621    if (yy < 0) yy = 0;
1622    else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
1623
1624    wd->show.show = EINA_TRUE;
1625    wd->show.x = xx;
1626    wd->show.y = yy;
1627    wd->show.w = ow;
1628    wd->show.h = oh;
1629
1630    if (wd->calc_job) ecore_job_del(wd->calc_job);
1631    wd->calc_job = ecore_job_add(_calc_job, wd);
1632 }
1633
1634 static Eina_Bool
1635 _zoom_timeout(void *data)
1636 {
1637    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1638    Widget_Data *wd = elm_widget_data_get(data);
1639
1640    if (!wd) return ECORE_CALLBACK_CANCEL;
1641    wd->zoom_timer = NULL;
1642    wd->pinch.level = 1.0;
1643    zoom_do(data);
1644    evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
1645    return ECORE_CALLBACK_CANCEL;
1646 }
1647
1648 static Eina_Bool
1649 _zoom_anim(void *data)
1650 {
1651    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1652    Evas_Object *obj = data;
1653    Widget_Data *wd = elm_widget_data_get(obj);
1654
1655    if (!wd) return ECORE_CALLBACK_CANCEL;
1656    if (wd->zoom_method == ZOOM_METHOD_IN) wd->t += 0.1 ;
1657    else if (wd->zoom_method == ZOOM_METHOD_OUT) wd->t -= 0.05;
1658    else
1659      {
1660         wd->zoom_animator = NULL;
1661         zoom_do(obj);
1662         evas_object_smart_callback_call(data, SIG_ZOOM_STOP, NULL);
1663         return ECORE_CALLBACK_CANCEL;
1664      }
1665
1666    if (wd->t >= 2.0)
1667      {
1668         wd->zoom_animator = NULL;
1669         wd->pinch.level = 2.0;
1670         if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1671         wd->zoom_timer = ecore_timer_add(0.35, _zoom_timeout, obj);
1672         return ECORE_CALLBACK_CANCEL;
1673      }
1674    else if (wd->t <= 0.5)
1675      {
1676         wd->zoom_animator = NULL;
1677         wd->pinch.level = 0.5;
1678         if (wd->zoom_timer) ecore_timer_del(wd->zoom_timer);
1679         wd->zoom_timer = ecore_timer_add(1.35, _zoom_timeout, obj);
1680         return ECORE_CALLBACK_CANCEL;
1681      }
1682    else if (wd->t != 1.0)
1683      {
1684         Evas_Coord x, y, w, h;
1685         float half_w, half_h;
1686         evas_object_geometry_get(data, &x, &y, &w, &h);
1687         half_w = (float)w * 0.5;
1688         half_h = (float)h * 0.5;
1689         wd->pinch.cx = x + half_w;
1690         wd->pinch.cy = y + half_h;
1691         wd->pinch.level = wd->t;
1692         if (wd->calc_job) ecore_job_del(wd->calc_job);
1693         wd->calc_job = ecore_job_add(_calc_job, wd);
1694      }
1695    return ECORE_CALLBACK_RENEW;
1696 }
1697
1698 static Eina_Bool
1699 _long_press(void *data)
1700 {
1701    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
1702    Widget_Data *wd = elm_widget_data_get(data);
1703
1704    if (!wd) return ECORE_CALLBACK_CANCEL;
1705    wd->long_timer = NULL;
1706    evas_object_smart_callback_call(data, SIG_LONGPRESSED, &wd->ev);
1707    return ECORE_CALLBACK_CANCEL;
1708 }
1709
1710 static void
1711 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1712 {
1713    ELM_CHECK_WIDTYPE(data, widtype);
1714    Widget_Data *wd = elm_widget_data_get(data);
1715    Evas_Event_Mouse_Down *ev = event_info;
1716    Event *ev0;
1717
1718    if (!wd) return;
1719    ev0 = get_event_object(data, 0);
1720    if (ev0) return;
1721    ev0 = create_event_object(data, obj, 0);
1722    if (!ev0) return;
1723
1724    ev0->hold_timer = NULL;
1725    ev0->prev.x = ev->canvas.x;
1726    ev0->prev.y = ev->canvas.y;
1727
1728    if (ev->button != 1) return;
1729    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1730    else wd->on_hold = EINA_FALSE;
1731    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1732      evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, ev);
1733    else
1734      evas_object_smart_callback_call(data, SIG_PRESS, ev);
1735    if (wd->long_timer) ecore_timer_del(wd->long_timer);
1736    wd->ev.canvas.x = ev->output.x;
1737    wd->ev.canvas.y = ev->output.y;
1738    wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1739 }
1740
1741 static void
1742 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1743 {
1744    Evas_Event_Mouse_Move *move = event_info;
1745    Event *ev0;
1746
1747    ev0 = get_event_object(data, 0);
1748    if (!ev0) return;
1749    ev0->prev.x = move->cur.canvas.x;
1750    ev0->prev.y = move->cur.canvas.y;
1751 }
1752
1753 static void
1754 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1755 {
1756    ELM_CHECK_WIDTYPE(data, widtype);
1757    Widget_Data *wd = elm_widget_data_get(data);
1758
1759    if (!wd) return;
1760    Evas_Event_Mouse_Up *ev = event_info;
1761    int mdevice;
1762    Event *ev0;
1763    Event *ev1;
1764
1765    ev0 = get_event_object(data, 0);
1766    if (ev0)
1767      {
1768         mdevice = get_multi_device(data);
1769         if (mdevice == 0)
1770           {
1771              if (ev0->hold_timer)
1772                {
1773                   ecore_timer_del(ev0->hold_timer);
1774                   ev0->hold_timer = NULL;
1775                }
1776              elm_smart_scroller_hold_set(wd->scr, 0);
1777              elm_smart_scroller_freeze_set(wd->scr, 0);
1778           }
1779         else
1780           {
1781              ev1 = get_event_object(data, mdevice);
1782              if (ev1)
1783                ev1->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev1);
1784           }
1785         destroy_event_object(data, ev0);
1786      }
1787
1788    if (ev->button != 1) return;
1789    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
1790    else wd->on_hold = EINA_FALSE;
1791    if (wd->long_timer)
1792      {
1793         ecore_timer_del(wd->long_timer);
1794         wd->long_timer = NULL;
1795      }
1796    if (!wd->on_hold) evas_object_smart_callback_call(data, SIG_CLICKED, ev);
1797    wd->on_hold = EINA_FALSE;
1798 }
1799
1800 static void
1801 _mouse_multi_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1802 {
1803    ELM_CHECK_WIDTYPE(data, widtype);
1804    Widget_Data *wd = elm_widget_data_get(data);
1805    Event *ev;
1806    Evas_Event_Multi_Down *down = event_info;
1807
1808    elm_smart_scroller_hold_set(wd->scr, 1);
1809    elm_smart_scroller_freeze_set(wd->scr, 1);
1810
1811    ev = create_event_object(data, obj, down->device);
1812    if (!ev)
1813      {
1814         DBG("Failed : create_event_object");
1815         goto done;
1816      }
1817    wd->multi_count++;
1818
1819    ev->hold_timer = NULL;
1820    ev->start.x = ev->prev.x = down->canvas.x;
1821    ev->start.y = ev->prev.y = down->canvas.y;
1822    ev->pinch_start_dis = 0;
1823    wd->pinch.level = 1.0;
1824    wd->pinch.diff = 1.0;
1825
1826 done:
1827    if (wd->long_timer)
1828      {
1829         ecore_timer_del(wd->long_timer);
1830         wd->long_timer = NULL;
1831      }
1832    return;
1833 }
1834
1835 static void
1836 _mouse_multi_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1837 {
1838    ELM_CHECK_WIDTYPE(data, widtype);
1839    Widget_Data *wd = elm_widget_data_get(data);
1840    Evas_Event_Multi_Move *move = event_info;
1841    int dis_new, dx, dy;
1842    double t, tt, a, a_diff;
1843    Event *ev0;
1844    Event *ev;
1845
1846    if ((!wd) || (!wd->src)) return;
1847    ev = get_event_object(data, move->device);
1848    if (!ev) return;
1849
1850    ev0 = get_event_object(data, 0);
1851    if (!ev0) return;
1852
1853    if (wd->multi_count >= 1)
1854      {
1855         Evas_Coord x, y, w, h;
1856         float half_w, half_h;
1857
1858         evas_object_geometry_get(data, &x, &y, &w, &h);
1859         half_w = (float)w * 0.5;
1860         half_h = (float)h * 0.5;
1861         dx = ev0->prev.x - ev->prev.x;
1862         dy = ev0->prev.y - ev->prev.y;
1863         dis_new = sqrt((dx * dx) + (dy * dy));
1864
1865         if (!ev->pinch_start_dis) ev->pinch_start_dis = dis_new;
1866         else
1867           {
1868              ev->pinch_dis = dis_new;
1869              tt = wd->pinch.diff;
1870              wd->pinch.diff = (double)(ev->pinch_dis - ev->pinch_start_dis);
1871              t = (wd->pinch.diff * 0.01) + 1.0;
1872              if ((t > 1.1) || (wd->rotate.doing))
1873                {
1874                   if (((wd->zoom + (int)t - 1) < wd->src->zoom_min) ||
1875                       ((wd->zoom + (int)t - 1) > wd->src->zoom_max) ||
1876                       (t > PINCH_ZOOM_MAX) || (t < PINCH_ZOOM_MIN))
1877                     {
1878                        wd->pinch.diff = tt;
1879                        goto do_nothing;
1880                     }
1881                   else
1882                     {
1883                        wd->pinch.level = (wd->pinch.diff * 0.01) + 1.0;
1884                        wd->pinch.cx = x + half_w;
1885                        wd->pinch.cy = y + half_h;
1886                        wd->pinch.doing = EINA_TRUE;
1887                        if (!wd->rotate.doing) goto do_zoom_only;
1888                     }
1889                }
1890              else
1891                {
1892                   if (wd->pinch.doing) goto do_nothing;
1893                }
1894
1895              a = (double)(ev->prev.y - ev0->prev.y) / (double)(ev->prev.x - ev0->prev.x);
1896              if (!wd->rotate.a) wd->rotate.a = a;
1897              else
1898                {
1899                   a_diff = wd->rotate.a - a;
1900                   if (a_diff > 0) wd->rotate.d -= 1.0;
1901                   else if (a_diff < 0) wd->rotate.d += 1.0;
1902                   wd->rotate.a = a;
1903                   wd->rotate.cx = x + half_w;
1904                   wd->rotate.cy = y + half_h;
1905                   wd->rotate.doing = EINA_TRUE;
1906                }
1907 do_zoom_only:
1908              if (wd->calc_job) ecore_job_del(wd->calc_job);
1909              wd->calc_job = ecore_job_add(_calc_job, wd);
1910           }
1911      }
1912 do_nothing:
1913    ev->prev.x = move->cur.canvas.x;
1914    ev->prev.y = move->cur.canvas.y;
1915 }
1916
1917 static void
1918 _mouse_multi_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1919 {
1920    ELM_CHECK_WIDTYPE(data, widtype);
1921    Widget_Data *wd = elm_widget_data_get(data);
1922    Evas_Event_Multi_Up *up = event_info;
1923    Event *ev0;
1924    Event *ev;
1925    Eina_Bool tp;
1926    int zoom = 0;
1927
1928    wd->multi_count--;
1929    if (wd->calc_job) ecore_job_del(wd->calc_job);
1930    if (wd->zoom_animator)
1931      {
1932         ecore_animator_del(wd->zoom_animator);
1933         wd->zoom_animator = NULL;
1934      }
1935    tp = wd->paused;
1936    wd->paused = EINA_TRUE;
1937    if (wd->pinch.diff >= 0.0) zoom = (int)ceil((wd->pinch.diff * 0.01) - 1.0);
1938    else if (wd->pinch.diff < 0.0) zoom = (int)floor(-1.0 / ((wd->pinch.diff * 0.005) + 1.0));
1939    elm_map_zoom_set(data, wd->zoom + zoom);
1940    wd->pinch.level = 1.0;
1941    wd->pinch.doing = EINA_FALSE;
1942    wd->paused = tp;
1943    wd->rotate.a = 0.0;
1944    wd->rotate.doing = EINA_FALSE;
1945
1946    ev = get_event_object(data, up->device);
1947    if (!ev)
1948      {
1949         DBG("Cannot get multi device");
1950         return;
1951      }
1952
1953    ev0 = get_event_object(data, 0);
1954    if (ev0)
1955      ev0->hold_timer = ecore_timer_add(0.35, _hold_timer_cb, ev0);
1956    else
1957      {
1958         if (ev->hold_timer)
1959           {
1960              ecore_timer_del(ev->hold_timer);
1961              ev->hold_timer = NULL;
1962           }
1963      }
1964    destroy_event_object(data, ev);
1965 }
1966
1967 static void
1968 _mouse_wheel_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1969 {
1970    ELM_CHECK_WIDTYPE(data, widtype);
1971    Widget_Data *wd = elm_widget_data_get(data);
1972    Evas_Event_Mouse_Wheel *ev = (Evas_Event_Mouse_Wheel*) event_info;
1973    Evas_Coord x, y, w, h;
1974    float half_w, half_h;
1975
1976    if (!wd) return;
1977    evas_object_geometry_get(data, &x, &y, &w, &h);
1978    half_w = (float)w * 0.5;
1979    half_h = (float)h * 0.5;
1980
1981    if (ev->z > 0)
1982      {
1983         wd->zoom_method = ZOOM_METHOD_OUT;
1984         wd->wheel_zoom -= 0.1;
1985         if (wd->wheel_zoom <= -2.0) wd->wheel_zoom = -2.0;
1986      }
1987    else
1988      {
1989         wd->zoom_method = ZOOM_METHOD_IN;
1990         wd->wheel_zoom += 0.1;
1991         if (wd->wheel_zoom >= 2.0) wd->wheel_zoom = 2.0;
1992      }
1993
1994    if (!wd->paused)
1995      {
1996         wd->pinch.level = pow(2.0, wd->wheel_zoom);
1997         wd->pinch.cx = x + half_w;
1998         wd->pinch.cy = y + half_h;
1999         if (wd->calc_job) ecore_job_del(wd->calc_job);
2000         wd->calc_job = ecore_job_add(_calc_job, wd);
2001      }
2002
2003    if (wd->wheel_timer) ecore_timer_del(wd->wheel_timer);
2004    wd->wheel_timer = ecore_timer_add(0.35, _wheel_timer_cb, data);
2005 }
2006
2007
2008 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
2009
2010 static Eina_Bool
2011 _hold_timer_cb(void *data)
2012 {
2013    Event *ev0 = data;
2014
2015    ev0->hold_timer = NULL;
2016    return ECORE_CALLBACK_CANCEL;
2017 }
2018
2019 static Eina_Bool
2020 _wheel_timer_cb(void *data)
2021 {
2022    ELM_CHECK_WIDTYPE(data, widtype) ECORE_CALLBACK_CANCEL;
2023    Widget_Data *wd = elm_widget_data_get(data);
2024    int zoom;
2025
2026    if (!wd) return ECORE_CALLBACK_CANCEL;
2027    if (wd->zoom_method == ZOOM_METHOD_IN) zoom = (int)ceil(wd->wheel_zoom);
2028    else if (wd->zoom_method == ZOOM_METHOD_OUT) zoom = (int)floor(wd->wheel_zoom);
2029    else
2030      {
2031         wd->wheel_timer = NULL;
2032         return ECORE_CALLBACK_CANCEL;
2033      }
2034
2035    wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
2036    wd->pinch.level = 1.0;
2037    elm_map_zoom_set(data, wd->zoom + zoom);
2038    wd->wheel_zoom = 0.0;
2039    wd->wheel_timer = NULL;
2040    wd->zoom_method = ZOOM_METHOD_NONE;
2041    return ECORE_CALLBACK_CANCEL;
2042 }
2043
2044 static void
2045 _rect_resize_cb(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2046 {
2047    ELM_CHECK_WIDTYPE(data, widtype);
2048    Widget_Data *wd = elm_widget_data_get(data);
2049    int x, y, w, h;
2050
2051    evas_object_geometry_get(wd->rect, &x, &y, &w, &h);
2052    evas_object_geometry_get(wd->pan_smart, &x, &y, &w, &h);
2053    evas_object_resize(wd->rect, w, h);
2054    evas_object_move(wd->rect, x, y);
2055 }
2056
2057 static void
2058 _del_hook(Evas_Object *obj)
2059 {
2060    ELM_CHECK_WIDTYPE(obj, widtype);
2061    Widget_Data *wd = elm_widget_data_get(obj);
2062    Elm_Map_Group_Class *group_clas;
2063    Elm_Map_Marker_Class *marker_clas;
2064    Eina_List *l;
2065    Event *ev;
2066    Evas_Object *p;
2067    Path_Node *n;
2068    Path_Waypoint *w;
2069    Ecore_Event_Handler *h;
2070    Elm_Map_Route *r;
2071    Elm_Map_Name *na;
2072    Evas_Object *route;
2073
2074    if (!wd) return;
2075    EINA_LIST_FREE(wd->groups_clas, group_clas)
2076      {
2077         if (group_clas->style)
2078           eina_stringshare_del(group_clas->style);
2079         free(group_clas);
2080      }
2081
2082    EINA_LIST_FREE(wd->markers_clas, marker_clas)
2083      {
2084         if (marker_clas->style)
2085           eina_stringshare_del(marker_clas->style);
2086         free(marker_clas);
2087      }
2088
2089    EINA_LIST_FOREACH(wd->s_event_list, l, ev)
2090      {
2091         destroy_event_object(obj, ev);
2092      }
2093
2094    EINA_LIST_FOREACH(wd->route, l, r)
2095      {
2096         EINA_LIST_FREE(r->path, p)
2097           {
2098              evas_object_del(p);
2099           }
2100
2101         EINA_LIST_FREE(r->waypoint, w)
2102           {
2103              if (w->point) eina_stringshare_del(w->point);
2104              free(w);
2105           }
2106
2107         EINA_LIST_FREE(r->nodes, n)
2108           {
2109              if (n->pos.address) eina_stringshare_del(n->pos.address);
2110              free(n);
2111           }
2112
2113         EINA_LIST_FREE(r->handlers, h)
2114           {
2115              ecore_event_handler_del(h);
2116           }
2117
2118         if (r->con_url) ecore_con_url_free(r->con_url);
2119         if (r->info.nodes) eina_stringshare_del(r->info.nodes);
2120         if (r->info.waypoints) eina_stringshare_del(r->info.waypoints);
2121      }
2122
2123    EINA_LIST_FREE(wd->names, na)
2124      {
2125         if (na->address) free(na->address);
2126         if (na->handler) ecore_event_handler_del(na->handler);
2127         if (na->ud.fname)
2128           {
2129              ecore_file_remove(na->ud.fname);
2130              free(na->ud.fname);
2131              na->ud.fname = NULL;
2132           }
2133      }
2134
2135    EINA_LIST_FREE(wd->track, route)
2136      {
2137         evas_object_del(route);
2138      }
2139
2140    if (wd->map) evas_map_free(wd->map);
2141    if (wd->source_names) free(wd->source_names);
2142    if (wd->calc_job) ecore_job_del(wd->calc_job);
2143    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
2144    if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
2145    if (wd->long_timer) ecore_timer_del(wd->long_timer);
2146    if (wd->user_agent) eina_stringshare_del(wd->user_agent);
2147    if (wd->ua) eina_hash_free(wd->ua);
2148    if (wd->markers) free(wd->markers);
2149
2150    free(wd);
2151 }
2152
2153 static void
2154 _del_pre_hook(Evas_Object *obj)
2155 {
2156    ELM_CHECK_WIDTYPE(obj, widtype);
2157    Widget_Data *wd = elm_widget_data_get(obj);
2158    Marker_Group *group;
2159    Elm_Map_Marker *marker;
2160    int i;
2161    Eina_Bool free_marker = EINA_TRUE;
2162    Eina_List *l;
2163
2164    if (!wd) return;
2165    grid_clearall(obj);
2166    for (i = 0; i <= wd->zoom_max; i++)
2167      {
2168         if (!wd->markers[i]) continue;
2169         Eina_Iterator *it = eina_matrixsparse_iterator_new(wd->markers[i]);
2170         Eina_Matrixsparse_Cell *cell;
2171
2172         EINA_ITERATOR_FOREACH(it, cell)
2173           {
2174              l =  eina_matrixsparse_cell_data_get(cell);
2175              EINA_LIST_FREE(l, group)
2176                {
2177                   EINA_LIST_FREE(group->markers, marker)
2178                     {
2179                        evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2180                                                            _bubble_sc_hints_changed_cb, group);
2181                        if (free_marker) free(marker);
2182                     }
2183                   free(group);
2184                }
2185              free_marker = EINA_FALSE;
2186           }
2187         eina_iterator_free(it);
2188         eina_matrixsparse_free(wd->markers[i]);
2189      }
2190
2191    evas_object_del(wd->sep_maps_markers);
2192    evas_object_del(wd->pan_smart);
2193    wd->pan_smart = NULL;
2194 }
2195
2196 static void
2197 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
2198 {
2199    ELM_CHECK_WIDTYPE(obj, widtype);
2200    Widget_Data *wd = elm_widget_data_get(obj);
2201
2202    if (!wd) return;
2203    if (elm_widget_focus_get(obj))
2204      {
2205         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
2206         evas_object_focus_set(wd->obj, EINA_TRUE);
2207      }
2208    else
2209      {
2210         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
2211         evas_object_focus_set(wd->obj, EINA_FALSE);
2212      }
2213 }
2214
2215 static void
2216 _theme_hook(Evas_Object *obj)
2217 {
2218    ELM_CHECK_WIDTYPE(obj, widtype);
2219    Widget_Data *wd = elm_widget_data_get(obj);
2220
2221    if (!wd) return;
2222    elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", elm_widget_style_get(obj));
2223    //   edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
2224    _sizing_eval(obj);
2225 }
2226
2227 static void
2228 _sizing_eval(Evas_Object *obj)
2229 {
2230    ELM_CHECK_WIDTYPE(obj, widtype);
2231    Widget_Data *wd = elm_widget_data_get(obj);
2232    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
2233
2234    if (!wd) return;
2235    evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
2236    evas_object_size_hint_min_set(obj, minw, minh);
2237    evas_object_size_hint_max_set(obj, maxw, maxh);
2238 }
2239
2240 static void
2241 _calc_job(void *data)
2242 {
2243    Widget_Data *wd = data;
2244    Evas_Coord minw, minh;
2245
2246    if (!wd) return;
2247    minw = wd->size.w;
2248    minh = wd->size.h;
2249    if (wd->resized)
2250      {
2251         wd->resized = EINA_FALSE;
2252         if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
2253           {
2254              double tz = wd->zoom;
2255              wd->zoom = 0.0;
2256              elm_map_zoom_set(wd->obj, tz);
2257           }
2258      }
2259    if ((minw != wd->minw) || (minh != wd->minh))
2260      {
2261         wd->minw = minw;
2262         wd->minh = minh;
2263         evas_object_smart_callback_call(wd->pan_smart, SIG_CHANGED, NULL);
2264         _sizing_eval(wd->obj);
2265      }
2266    wd->calc_job = NULL;
2267    evas_object_smart_changed(wd->pan_smart);
2268 }
2269
2270 static void
2271 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2272 {
2273    Pan *sd = evas_object_smart_data_get(obj);
2274    if (!sd) return;
2275    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2276    sd->wd->pan_x = x;
2277    sd->wd->pan_y = y;
2278    evas_object_smart_changed(obj);
2279 }
2280
2281 static void
2282 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2283 {
2284    Pan *sd = evas_object_smart_data_get(obj);
2285    if (!sd) return;
2286    if (x) *x = sd->wd->pan_x;
2287    if (y) *y = sd->wd->pan_y;
2288 }
2289
2290 static void
2291 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
2292 {
2293    Pan *sd = evas_object_smart_data_get(obj);
2294    Evas_Coord ow, oh;
2295    if (!sd) return;
2296    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2297    ow = sd->wd->minw - ow;
2298    if (ow < 0) ow = 0;
2299    oh = sd->wd->minh - oh;
2300    if (oh < 0) oh = 0;
2301    if (x) *x = ow;
2302    if (y) *y = oh;
2303 }
2304
2305 static void
2306 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
2307 {
2308    if (x) *x = 0;
2309    if (y) *y = 0;
2310 }
2311
2312 static void
2313 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
2314 {
2315    Pan *sd = evas_object_smart_data_get(obj);
2316    if (!sd) return;
2317    if (w) *w = sd->wd->minw;
2318    if (h) *h = sd->wd->minh;
2319 }
2320
2321 static void
2322 _pan_add(Evas_Object *obj)
2323 {
2324    Pan *sd;
2325    Evas_Object_Smart_Clipped_Data *cd;
2326    _pan_sc.add(obj);
2327    cd = evas_object_smart_data_get(obj);
2328    if (!cd) return;
2329    sd = calloc(1, sizeof(Pan));
2330    if (!sd) return;
2331    sd->__clipped_data = *cd;
2332    free(cd);
2333    evas_object_smart_data_set(obj, sd);
2334 }
2335
2336 static void
2337 _pan_del(Evas_Object *obj)
2338 {
2339    Pan *sd = evas_object_smart_data_get(obj);
2340    if (!sd) return;
2341    _pan_sc.del(obj);
2342 }
2343
2344 static void
2345 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2346 {
2347    Pan *sd = evas_object_smart_data_get(obj);
2348    Evas_Coord ow, oh;
2349    if (!sd) return;
2350    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2351    if ((ow == w) && (oh == h)) return;
2352    sd->wd->resized = EINA_TRUE;
2353    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2354    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2355 }
2356
2357 static void
2358 _pan_calculate(Evas_Object *obj)
2359 {
2360    Pan *sd = evas_object_smart_data_get(obj);
2361    Evas_Coord ox, oy, ow, oh;
2362    Eina_List *l;
2363    Grid *g;
2364    if (!sd) return;
2365    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2366    rect_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2367    EINA_LIST_FOREACH(sd->wd->grids, l, g)
2368      {
2369         if (sd->wd->zoom == g->zoom) grid_load(sd->wd->obj, g);
2370         grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2371         marker_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2372         if (!sd->wd->zoom_animator) route_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2373         if (!sd->wd->zoom_animator) track_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
2374      }
2375 }
2376
2377 static void
2378 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
2379 {
2380    Pan *sd = evas_object_smart_data_get(obj);
2381    if (!sd) return;
2382    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2383    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2384 }
2385
2386 static void
2387 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2388 {
2389    ELM_CHECK_WIDTYPE(obj, widtype);
2390    Widget_Data *wd = elm_widget_data_get(obj);
2391
2392    if (!wd) return;
2393    elm_smart_scroller_hold_set(wd->scr, 1);
2394 }
2395
2396 static void
2397 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2398 {
2399    ELM_CHECK_WIDTYPE(obj, widtype);
2400    Widget_Data *wd = elm_widget_data_get(obj);
2401
2402    if (!wd) return;
2403    elm_smart_scroller_hold_set(wd->scr, 0);
2404 }
2405
2406 static void
2407 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2408 {
2409    ELM_CHECK_WIDTYPE(obj, widtype);
2410    Widget_Data *wd = elm_widget_data_get(obj);
2411
2412    if (!wd) return;
2413    elm_smart_scroller_freeze_set(wd->scr, 1);
2414 }
2415
2416 static void
2417 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2418 {
2419    ELM_CHECK_WIDTYPE(obj, widtype);
2420    Widget_Data *wd = elm_widget_data_get(obj);
2421
2422    if (!wd) return;
2423    elm_smart_scroller_freeze_set(wd->scr, 0);
2424 }
2425
2426 static void
2427 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2428 {
2429    evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
2430 }
2431
2432 static void
2433 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2434 {
2435    evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
2436 }
2437
2438 static void
2439 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2440 {
2441    Widget_Data *wd = elm_widget_data_get(data);
2442    wd->center_on.enabled = EINA_FALSE;
2443    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
2444 }
2445
2446 static void
2447 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2448 {
2449    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
2450 }
2451
2452 static void
2453 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2454 {
2455    evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
2456 }
2457
2458
2459 static void
2460 _group_object_create(Marker_Group *group)
2461 {
2462    const char *style = "radio";
2463    Evas_Object *icon = NULL;
2464
2465    if (group->obj) return;
2466    if ((!group->clas->priv.objs_notused) || (eina_list_count(group->markers) == 1))
2467      {
2468         //set icon and style
2469         if (eina_list_count(group->markers) == 1)
2470           {
2471              Elm_Map_Marker *m = eina_list_data_get(group->markers);
2472              if (m->clas->style)
2473                style = m->clas->style;
2474
2475              if (m->clas->func.icon_get)
2476                icon = m->clas->func.icon_get(group->wd->obj, m, m->data);
2477
2478              group->delete_object = EINA_TRUE;
2479           }
2480         else
2481           {
2482              if (group->clas->style)
2483                style = group->clas->style;
2484
2485              if (group->clas->func.icon_get)
2486                icon = group->clas->func.icon_get(group->wd->obj, group->clas->data);
2487
2488              group->delete_object = EINA_FALSE;
2489           }
2490
2491         group->obj = elm_layout_add(group->wd->obj);
2492         elm_layout_theme_set(group->obj, "map/marker", style, elm_widget_style_get(group->wd->obj));
2493
2494         if (icon) elm_object_part_content_set(group->obj, "elm.icon", icon);
2495
2496         evas_object_smart_member_add(group->obj, group->wd->pan_smart);
2497         elm_widget_sub_object_add(group->wd->obj, group->obj);
2498         evas_object_stack_above(group->obj, group->wd->sep_maps_markers);
2499
2500         if (!group->delete_object)
2501           group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
2502      }
2503    else
2504      {
2505         group->delete_object = EINA_FALSE;
2506
2507         group->obj = eina_list_data_get(group->clas->priv.objs_notused);
2508         group->clas->priv.objs_used = eina_list_append(group->clas->priv.objs_used, group->obj);
2509         group->clas->priv.objs_notused = eina_list_remove(group->clas->priv.objs_notused, group->obj);
2510         evas_object_show(group->obj);
2511      }
2512
2513    edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb, group);
2514    edje_object_signal_callback_add(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb, group);
2515
2516    group->update_nbelems = EINA_TRUE;
2517    group->update_resize = EINA_TRUE;
2518    group->update_raise = EINA_TRUE;
2519
2520    if (group->open) _group_bubble_create(group);
2521 }
2522
2523 static void
2524 _group_object_free(Marker_Group *group)
2525 {
2526    if (!group->obj) return;
2527    if (!group->delete_object)
2528      {
2529         group->clas->priv.objs_notused = eina_list_append(group->clas->priv.objs_notused, group->obj);
2530         group->clas->priv.objs_used = eina_list_remove(group->clas->priv.objs_used, group->obj);
2531         evas_object_hide(group->obj);
2532
2533         edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "open", "elm", _group_open_cb);
2534         edje_object_signal_callback_del(elm_layout_edje_get(group->obj), "bringin", "elm", _group_bringin_cb);
2535      }
2536    else
2537      evas_object_del(group->obj);
2538
2539    group->obj = NULL;
2540    _group_bubble_free(group);
2541 }
2542
2543 static void
2544 _group_bubble_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2545 {
2546    Marker_Group *group = data;
2547
2548    if (!evas_object_above_get(group->rect)) return;
2549    evas_object_raise(group->bubble);
2550    evas_object_raise(group->sc);
2551    evas_object_raise(group->rect);
2552 }
2553
2554 static void
2555 _group_bubble_create(Marker_Group *group)
2556 {
2557    if (group->bubble) return;
2558
2559    group->wd->opened_bubbles = eina_list_append(group->wd->opened_bubbles, group);
2560    group->bubble = edje_object_add(evas_object_evas_get(group->obj));
2561    _elm_theme_object_set(group->wd->obj, group->bubble, "map", "marker_bubble",
2562                          elm_widget_style_get(group->wd->obj));
2563    evas_object_smart_member_add(group->bubble,
2564                                 group->wd->obj);
2565    elm_widget_sub_object_add(group->wd->obj, group->bubble);
2566
2567    _group_bubble_content_free(group);
2568    if (!_group_bubble_content_update(group))
2569      {
2570         //no content, we can delete the bubble
2571         _group_bubble_free(group);
2572         return;
2573      }
2574
2575    group->rect = evas_object_rectangle_add(evas_object_evas_get(group->obj));
2576    evas_object_color_set(group->rect, 0, 0, 0, 0);
2577    evas_object_repeat_events_set(group->rect, EINA_TRUE);
2578    evas_object_smart_member_add(group->rect, group->wd->obj);
2579    elm_widget_sub_object_add(group->wd->obj, group->rect);
2580
2581    evas_object_event_callback_add(group->rect, EVAS_CALLBACK_MOUSE_UP, _group_bubble_mouse_up_cb, group);
2582
2583    _group_bubble_place(group);
2584 }
2585
2586 static void _bubble_sc_hints_changed_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2587 {
2588    _group_bubble_place(data);
2589 }
2590
2591 static int
2592 _group_bubble_content_update(Marker_Group *group)
2593 {
2594    Eina_List *l;
2595    Elm_Map_Marker *marker;
2596    int i = 0;
2597
2598    if (!group->bubble) return 1;
2599
2600    if (!group->sc)
2601      {
2602         group->sc = elm_scroller_add(group->bubble);
2603         elm_widget_style_set(group->sc, "map_bubble");
2604         elm_scroller_content_min_limit(group->sc, EINA_FALSE, EINA_TRUE);
2605         elm_scroller_policy_set(group->sc, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
2606         elm_scroller_bounce_set(group->sc, _elm_config->thumbscroll_bounce_enable, EINA_FALSE);
2607         edje_object_part_swallow(group->bubble, "elm.swallow.content", group->sc);
2608         evas_object_show(group->sc);
2609         evas_object_smart_member_add(group->sc,
2610                                      group->wd->obj);
2611         elm_widget_sub_object_add(group->wd->obj, group->sc);
2612
2613         group->bx = elm_box_add(group->bubble);
2614         evas_object_size_hint_align_set(group->bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
2615         evas_object_size_hint_weight_set(group->bx, 0.5, 0.5);
2616         elm_box_horizontal_set(group->bx, EINA_TRUE);
2617         evas_object_show(group->bx);
2618
2619         elm_object_content_set(group->sc, group->bx);
2620
2621         evas_object_event_callback_add(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2622                                        _bubble_sc_hints_changed_cb, group);
2623      }
2624
2625    EINA_LIST_FOREACH(group->markers, l, marker)
2626      {
2627         if (i >= group->wd->markers_max_num) break;
2628         if ((!marker->content) && (marker->clas->func.get))
2629           marker->content = marker->clas->func.get(group->wd->obj, marker, marker->data);
2630         else if (marker->content)
2631           elm_box_unpack(group->bx, marker->content);
2632         if (marker->content)
2633           {
2634              elm_box_pack_end(group->bx, marker->content);
2635              i++;
2636           }
2637      }
2638    return i;
2639 }
2640
2641 static void
2642 _group_bubble_content_free(Marker_Group *group)
2643 {
2644    Eina_List *l;
2645    Elm_Map_Marker *marker;
2646
2647    if (!group->sc) return;
2648    EINA_LIST_FOREACH(group->markers, l, marker)
2649      {
2650         if ((marker->content) && (marker->clas->func.del))
2651           marker->clas->func.del(group->wd->obj, marker, marker->data, marker->content);
2652         else if (marker->content)
2653           evas_object_del(marker->content);
2654         marker->content = NULL;
2655      }
2656    evas_object_del(group->sc);
2657    group->sc = NULL;
2658 }
2659
2660 static void
2661 _group_bubble_free(Marker_Group *group)
2662 {
2663    if (!group->bubble) return;
2664    group->wd->opened_bubbles = eina_list_remove(group->wd->opened_bubbles, group);
2665    evas_object_event_callback_del_full(group->sc, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2666                                        _bubble_sc_hints_changed_cb, group);
2667    evas_object_del(group->bubble);
2668    evas_object_del(group->rect);
2669    group->bubble = NULL;
2670    _group_bubble_content_free(group);
2671 }
2672
2673 static void
2674 _group_bubble_place(Marker_Group *group)
2675 {
2676    Evas_Coord x, y, w;
2677    Evas_Coord xx, yy, ww, hh;
2678    const char *s;
2679
2680    if ((!group->bubble) || (!group->obj)) return;
2681
2682    evas_object_geometry_get(group->obj, &x, &y, &w, NULL);
2683    edje_object_size_min_calc(group->bubble, NULL, &hh);
2684
2685    s = edje_object_data_get(group->bubble, "size_w");
2686    if (s) ww = atoi(s);
2687    else ww = 0;
2688    xx = x + w / 2 - ww / 2;
2689    yy = y-hh;
2690
2691    evas_object_move(group->bubble, xx, yy);
2692    evas_object_resize(group->bubble, ww, hh);
2693    obj_rotate_zoom(group->wd, group->bubble);
2694    evas_object_show(group->bubble);
2695
2696    evas_object_move(group->rect, xx, yy);
2697    evas_object_resize(group->rect, ww, hh);
2698    obj_rotate_zoom(group->wd, group->rect);
2699    evas_object_show(group->rect);
2700 }
2701
2702 static void
2703 _group_bringin_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2704 {
2705    Marker_Group *group = data;
2706    Elm_Map_Marker *marker = eina_list_data_get(group->markers);
2707    if (!marker) return;
2708    group->bringin = EINA_TRUE;
2709    elm_map_geo_region_bring_in(group->wd->obj, marker->longitude, marker->latitude);
2710 }
2711
2712 static void
2713 _group_open_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *soure __UNUSED__)
2714 {
2715    Marker_Group *group = data;
2716
2717    if (group->bringin)
2718      {
2719         group->bringin = EINA_FALSE;
2720         return;
2721      }
2722
2723    if (group->bubble)
2724      {
2725         group->open = EINA_FALSE;
2726         _group_bubble_free(group);
2727         return;
2728      }
2729    group->open = EINA_TRUE;
2730    _group_bubble_create(group);
2731 }
2732
2733 static Eina_Bool
2734 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
2735 {
2736    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2737    Widget_Data *wd = elm_widget_data_get(obj);
2738    int zoom;
2739    Evas_Coord x = 0;
2740    Evas_Coord y = 0;
2741    Evas_Coord step_x = 0;
2742    Evas_Coord step_y = 0;
2743    Evas_Coord v_w = 0;
2744    Evas_Coord v_h = 0;
2745    Evas_Coord page_x = 0;
2746    Evas_Coord page_y = 0;
2747
2748    if (!wd) return EINA_FALSE;
2749    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
2750    Evas_Event_Key_Down *ev = event_info;
2751    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
2752
2753    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
2754    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
2755    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
2756    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
2757
2758    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
2759      {
2760         x -= step_x;
2761      }
2762    else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
2763      {
2764         x += step_x;
2765      }
2766    else if ((!strcmp(ev->keyname, "Up"))  || (!strcmp(ev->keyname, "KP_Up")))
2767      {
2768         y -= step_y;
2769      }
2770    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
2771      {
2772         y += step_y;
2773      }
2774    else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
2775      {
2776         if (page_y < 0)
2777           y -= -(page_y * v_h) / 100;
2778         else
2779           y -= page_y;
2780      }
2781    else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
2782      {
2783         if (page_y < 0)
2784           y += -(page_y * v_h) / 100;
2785         else
2786           y += page_y;
2787      }
2788    else if (!strcmp(ev->keyname, "KP_Add"))
2789      {
2790         zoom = elm_map_zoom_get(obj) + 1;
2791         elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2792         elm_map_zoom_set(obj, zoom);
2793         return EINA_TRUE;
2794      }
2795    else if (!strcmp(ev->keyname, "KP_Subtract"))
2796      {
2797         zoom = elm_map_zoom_get(obj) - 1;
2798         elm_map_zoom_mode_set(obj, ELM_MAP_ZOOM_MODE_MANUAL);
2799         elm_map_zoom_set(obj, zoom);
2800         return EINA_TRUE;
2801      }
2802    else return EINA_FALSE;
2803
2804    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2805    elm_smart_scroller_child_pos_set(wd->scr, x, y);
2806
2807    return EINA_TRUE;
2808 }
2809
2810 static Eina_Bool
2811 cb_dump_name_attrs(void *data, const char *key, const char *value)
2812 {
2813    Name_Dump *dump = (Name_Dump*)data;
2814    if (!dump) return EINA_FALSE;
2815
2816    if (!strncmp(key, NOMINATIM_ATTR_LON, sizeof(NOMINATIM_ATTR_LON))) dump->lon = atof(value);
2817    else if (!strncmp(key, NOMINATIM_ATTR_LAT, sizeof(NOMINATIM_ATTR_LAT))) dump->lat = atof(value);
2818
2819    return EINA_TRUE;
2820 }
2821
2822
2823 static Eina_Bool
2824 cb_route_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2825 {
2826    Route_Dump *dump = data;
2827    if (!dump) return EINA_FALSE;
2828
2829    switch (type)
2830      {
2831       case EINA_SIMPLE_XML_OPEN:
2832       case EINA_SIMPLE_XML_OPEN_EMPTY:
2833         {
2834            const char *attrs;
2835
2836            attrs = eina_simple_xml_tag_attributes_find(value, length);
2837            if (!attrs)
2838              {
2839                 if (!strncmp(value, YOURS_DISTANCE, length)) dump->id = ROUTE_XML_DISTANCE;
2840                 else if (!strncmp(value, YOURS_DESCRIPTION, length)) dump->id = ROUTE_XML_DESCRIPTION;
2841                 else if (!strncmp(value, YOURS_COORDINATES, length)) dump->id = ROUTE_XML_COORDINATES;
2842                 else dump->id = ROUTE_XML_NONE;
2843              }
2844          }
2845         break;
2846       case EINA_SIMPLE_XML_DATA:
2847         {
2848            char *buf = malloc(length);
2849            if (!buf) return EINA_FALSE;
2850            snprintf(buf, length, "%s", value);
2851            if (dump->id == ROUTE_XML_DISTANCE) dump->distance = atof(buf);
2852            else if (!(dump->description) && (dump->id == ROUTE_XML_DESCRIPTION)) dump->description = strdup(buf);
2853            else if (dump->id == ROUTE_XML_COORDINATES) dump->coordinates = strdup(buf);
2854            free(buf);
2855         }
2856         break;
2857       default:
2858         break;
2859      }
2860
2861    return EINA_TRUE;
2862 }
2863
2864 static Eina_Bool
2865 cb_name_dump(void *data, Eina_Simple_XML_Type type, const char *value, unsigned offset __UNUSED__, unsigned length)
2866 {
2867    Name_Dump *dump = data;
2868    if (!dump) return EINA_FALSE;
2869
2870    switch (type)
2871      {
2872       case EINA_SIMPLE_XML_OPEN:
2873       case EINA_SIMPLE_XML_OPEN_EMPTY:
2874         {
2875            const char *attrs;
2876            attrs = eina_simple_xml_tag_attributes_find(value, length);
2877            if (attrs)
2878              {
2879                 if (!strncmp(value, NOMINATIM_RESULT, sizeof(NOMINATIM_RESULT) - 1)) dump->id = NAME_XML_NAME;
2880                 else dump->id = NAME_XML_NONE;
2881
2882                 eina_simple_xml_attributes_parse
2883                   (attrs, length - (attrs - value), cb_dump_name_attrs, dump);
2884              }
2885         }
2886         break;
2887       case EINA_SIMPLE_XML_DATA:
2888         {
2889            char *buf = malloc(length + 1);
2890            if (!buf) return EINA_FALSE;
2891            snprintf(buf, length + 1, "%s", value);
2892            if (dump->id == NAME_XML_NAME) dump->address = strdup(buf);
2893            free(buf);
2894         }
2895         break;
2896       default:
2897         break;
2898      }
2899
2900    return EINA_TRUE;
2901 }
2902
2903 static void
2904 _parse_kml(void *data)
2905 {
2906    Elm_Map_Route *r = (Elm_Map_Route*)data;
2907    if (!r || !r->ud.fname) return;
2908
2909    FILE *f;
2910    char **str;
2911    unsigned int ele, idx;
2912    double lon, lat;
2913    Evas_Object *path;
2914
2915    Route_Dump dump = {0, r->ud.fname, 0.0, NULL, NULL};
2916
2917    f = fopen(r->ud.fname, "rb");
2918    if (f)
2919      {
2920         long sz;
2921
2922         fseek(f, 0, SEEK_END);
2923         sz = ftell(f);
2924         if (sz > 0)
2925           {
2926              char *buf;
2927
2928              fseek(f, 0, SEEK_SET);
2929              buf = malloc(sz);
2930              if (buf)
2931                {
2932                   if (fread(buf, 1, sz, f))
2933                     {
2934                        eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_route_dump, &dump);
2935                        free(buf);
2936                     }
2937                }
2938           }
2939         fclose(f);
2940
2941         if (dump.distance) r->info.distance = dump.distance;
2942         if (dump.description)
2943           {
2944              eina_stringshare_replace(&r->info.waypoints, dump.description);
2945              str = eina_str_split_full(dump.description, "\n", 0, &ele);
2946              r->info.waypoint_count = ele;
2947              for (idx = 0 ; idx < ele ; idx++)
2948                {
2949                   Path_Waypoint *wp = ELM_NEW(Path_Waypoint);
2950                   if (wp)
2951                     {
2952                        wp->wd = r->wd;
2953                        wp->point = eina_stringshare_add(str[idx]);
2954                        DBG("%s", str[idx]);
2955                        r->waypoint = eina_list_append(r->waypoint, wp);
2956                     }
2957                }
2958              if (str && str[0])
2959                {
2960                   free(str[0]);
2961                   free(str);
2962                }
2963           }
2964         else WRN("description is not found !");
2965
2966         if (dump.coordinates)
2967           {
2968              eina_stringshare_replace(&r->info.nodes, dump.coordinates);
2969              str = eina_str_split_full(dump.coordinates, "\n", 0, &ele);
2970              r->info.node_count = ele;
2971              for (idx = 0 ; idx < ele ; idx++)
2972                {
2973                   sscanf(str[idx], "%lf,%lf", &lon, &lat);
2974                   Path_Node *n = ELM_NEW(Path_Node);
2975                   if (n)
2976                     {
2977                        n->wd = r->wd;
2978                        n->pos.lon = lon;
2979                        n->pos.lat = lat;
2980                        n->idx = idx;
2981                        DBG("%lf:%lf", lon, lat);
2982                        n->pos.address = NULL;
2983                        r->nodes = eina_list_append(r->nodes, n);
2984
2985                        path = evas_object_polygon_add(evas_object_evas_get(r->wd->obj));
2986                        evas_object_smart_member_add(path, r->wd->pan_smart);
2987                        r->path = eina_list_append(r->path, path);
2988                     }
2989                }
2990              if (str && str[0])
2991                {
2992                   free(str[0]);
2993                   free(str);
2994                }
2995           }
2996      }
2997 }
2998
2999 static void
3000 _parse_name(void *data)
3001 {
3002    Elm_Map_Name *n = (Elm_Map_Name*)data;
3003    if (!n || !n->ud.fname) return;
3004
3005    FILE *f;
3006
3007    Name_Dump dump = {0, NULL, 0.0, 0.0};
3008
3009    f = fopen(n->ud.fname, "rb");
3010    if (f)
3011      {
3012         long sz;
3013
3014         fseek(f, 0, SEEK_END);
3015         sz = ftell(f);
3016         if (sz > 0)
3017           {
3018              char *buf;
3019
3020              fseek(f, 0, SEEK_SET);
3021              buf = malloc(sz);
3022              if (buf)
3023                {
3024                   if (fread(buf, 1, sz, f))
3025                     {
3026                        eina_simple_xml_parse(buf, sz, EINA_TRUE, cb_name_dump, &dump);
3027                        free(buf);
3028                     }
3029                }
3030           }
3031         fclose(f);
3032
3033         if (dump.address)
3034           {
3035              INF("[%lf : %lf] ADDRESS : %s", n->lon, n->lat, dump.address);
3036              n->address = strdup(dump.address);
3037           }
3038         n->lon = dump.lon;
3039         n->lat = dump.lat;
3040      }
3041 }
3042
3043 static Eina_Bool
3044 _route_complete_cb(void *data, int ev_type __UNUSED__, void *event)
3045 {
3046    Ecore_Con_Event_Url_Complete *ev = event;
3047    Elm_Map_Route *r = (Elm_Map_Route*)data;
3048    Widget_Data *wd = r->wd;
3049
3050    if ((!r) || (!ev)) return EINA_TRUE;
3051    Elm_Map_Route *rr = ecore_con_url_data_get(r->con_url);
3052    ecore_con_url_data_set(r->con_url, NULL);
3053    if (r!=rr) return EINA_TRUE;
3054
3055    if (r->ud.fd) fclose(r->ud.fd);
3056    _parse_kml(r);
3057
3058    if (wd->grids)
3059      {
3060         Evas_Coord ox, oy, ow, oh;
3061         evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
3062         route_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3063      }
3064    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3065                            "elm,state,busy,stop", "elm");
3066    evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOADED, NULL);
3067    return EINA_TRUE;
3068 }
3069
3070 static Eina_Bool
3071 _name_complete_cb(void *data, int ev_type __UNUSED__, void *event)
3072 {
3073    Ecore_Con_Event_Url_Complete *ev = event;
3074    Elm_Map_Name *n = (Elm_Map_Name*)data;
3075    Widget_Data *wd = n->wd;
3076
3077    if ((!n) || (!ev)) return EINA_TRUE;
3078    Elm_Map_Name *nn = ecore_con_url_data_get(n->con_url);
3079    ecore_con_url_data_set(n->con_url, NULL);
3080    if (n!=nn) return EINA_TRUE;
3081
3082    if (n->ud.fd) fclose(n->ud.fd);
3083    _parse_name(n);
3084
3085    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3086                            "elm,state,busy,stop", "elm");
3087    evas_object_smart_callback_call(wd->obj, SIG_NAME_LOADED, NULL);
3088    return EINA_TRUE;
3089 }
3090
3091 static Elm_Map_Name *
3092 _utils_convert_name(const Evas_Object *obj, int method, char *address, double lon, double lat)
3093 {
3094    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3095    Widget_Data *wd = elm_widget_data_get(obj);
3096    char buf[PATH_MAX];
3097    char *source;
3098    int fd;
3099
3100    if ((!wd) || (!wd->src)) return NULL;
3101    Elm_Map_Name *name = ELM_NEW(Elm_Map_Name);
3102    if (!name) return NULL;
3103
3104    snprintf(buf, sizeof(buf), DEST_NAME_XML_FILE);
3105    fd = mkstemp(buf);
3106    if (fd < 0)
3107      {
3108         free(name);
3109         return NULL;
3110      }
3111
3112    name->con_url = ecore_con_url_new(NULL);
3113    name->ud.fname = strdup(buf);
3114    INF("xml file : %s", name->ud.fname);
3115
3116    name->ud.fd = fdopen(fd, "w+");
3117    if ((!name->con_url) || (!name->ud.fd))
3118      {
3119         ecore_con_url_free(name->con_url);
3120         free(name);
3121         return NULL;
3122      }
3123
3124    name->wd = wd;
3125    name->handler = ecore_event_handler_add (ECORE_CON_EVENT_URL_COMPLETE, _name_complete_cb, name);
3126    name->method = method;
3127    if (method == ELM_MAP_NAME_METHOD_SEARCH) name->address = strdup(address);
3128    else if (method == ELM_MAP_NAME_METHOD_REVERSE) name->address = NULL;
3129    name->lon = lon;
3130    name->lat = lat;
3131
3132    source = wd->src->name_url_cb(wd->obj, method, address, lon, lat);
3133    INF("name url = %s", source);
3134
3135    wd->names = eina_list_append(wd->names, name);
3136    ecore_con_url_url_set(name->con_url, source);
3137    ecore_con_url_fd_set(name->con_url, fileno(name->ud.fd));
3138    ecore_con_url_data_set(name->con_url, name);
3139
3140    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
3141                            "elm,state,busy,start", "elm");
3142    evas_object_smart_callback_call(wd->obj, SIG_NAME_LOAD, NULL);
3143    ecore_con_url_get(name->con_url);
3144    if (source) free(source);
3145
3146    return name;
3147
3148 }
3149
3150 static int idnum = 1;
3151
3152 #endif
3153
3154 EAPI Evas_Object *
3155 elm_map_add(Evas_Object *parent)
3156 {
3157 #ifdef HAVE_ELEMENTARY_ECORE_CON
3158    Evas *e;
3159    Widget_Data *wd;
3160    Evas_Coord minw, minh;
3161    Evas_Object *obj;
3162    static Evas_Smart *smart = NULL;
3163    Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
3164
3165    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
3166
3167    ELM_SET_WIDTYPE(widtype, "map");
3168    elm_widget_type_set(obj, "map");
3169    elm_widget_sub_object_add(parent, obj);
3170    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
3171    elm_widget_data_set(obj, wd);
3172    elm_widget_del_hook_set(obj, _del_hook);
3173    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
3174    elm_widget_theme_hook_set(obj, _theme_hook);
3175    elm_widget_can_focus_set(obj, EINA_TRUE);
3176    elm_widget_event_hook_set(obj, _event_hook);
3177
3178    wd->scr = elm_smart_scroller_add(e);
3179    elm_smart_scroller_widget_set(wd->scr, obj);
3180    elm_smart_scroller_object_theme_set(obj, wd->scr, "map", "base", "default");
3181    evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
3182    evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
3183    elm_widget_resize_object_set(obj, wd->scr);
3184    elm_smart_scroller_wheel_disabled_set(wd->scr, EINA_TRUE);
3185
3186    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
3187    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
3188    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
3189    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
3190    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
3191
3192    elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
3193    source_init(obj);
3194
3195    wd->obj = obj;
3196    wd->map = evas_map_new(4);
3197    if (!wd->map) return NULL;
3198
3199    wd->zoom_min = 0xFF;
3200    wd->zoom_max = 0X00;
3201    wd->markers_max_num = 30;
3202    wd->pinch.level = 1.0;
3203    zoom_min_get(obj);
3204    zoom_max_get(obj);
3205    wd->markers = calloc(wd->zoom_max + 1, sizeof(void*));
3206
3207    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
3208    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
3209    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
3210    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
3211
3212    if (!smart)
3213      {
3214         static Evas_Smart_Class sc;
3215
3216         evas_object_smart_clipped_smart_set(&_pan_sc);
3217         sc = _pan_sc;
3218         sc.name = "elm_map_pan";
3219         sc.version = EVAS_SMART_CLASS_VERSION;
3220         sc.add = _pan_add;
3221         sc.del = _pan_del;
3222         sc.resize = _pan_resize;
3223         sc.move = _pan_move;
3224         sc.calculate = _pan_calculate;
3225         smart = evas_smart_class_new(&sc);
3226      }
3227    if (smart)
3228      {
3229         wd->pan_smart = evas_object_smart_add(e, smart);
3230         wd->pan = evas_object_smart_data_get(wd->pan_smart);
3231         wd->pan->wd = wd;
3232      }
3233
3234    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
3235                                      _pan_set, _pan_get, _pan_max_get,
3236                                      _pan_min_get, _pan_child_size_get);
3237
3238    wd->rect = evas_object_rectangle_add(e);
3239    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_RESIZE,
3240                                   _rect_resize_cb, obj);
3241    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_DOWN,
3242                                   _mouse_down, obj);
3243    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_MOVE,
3244                                   _mouse_move, obj);
3245    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_UP,
3246                                   _mouse_up, obj);
3247    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_DOWN,
3248                                   _mouse_multi_down, obj);
3249    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_MOVE,
3250                                   _mouse_multi_move, obj);
3251    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MULTI_UP,
3252                                   _mouse_multi_up, obj);
3253    evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL,
3254                                   _mouse_wheel_cb, obj);
3255
3256    evas_object_smart_member_add(wd->rect, wd->pan_smart);
3257    elm_widget_sub_object_add(obj, wd->rect);
3258    evas_object_show(wd->rect);
3259    evas_object_color_set(wd->rect, 0, 0, 0, 0);
3260
3261    wd->mode = ELM_MAP_ZOOM_MODE_MANUAL;
3262    wd->id = ((int)getpid() << 16) | idnum;
3263    idnum++;
3264
3265    wd->tsize = 256;
3266    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
3267                              &minw, &minh);
3268    evas_object_size_hint_min_set(obj, minw, minh);
3269
3270    wd->sep_maps_markers = evas_object_rectangle_add(evas_object_evas_get(obj));
3271    evas_object_smart_member_add(wd->sep_maps_markers, wd->pan_smart);
3272
3273    wd->paused = EINA_TRUE;
3274    elm_map_zoom_set(obj, 0);
3275    wd->paused = EINA_FALSE;
3276    _sizing_eval(obj);
3277
3278    // TODO: convert Elementary to subclassing of Evas_Smart_Class
3279    // TODO: and save some bytes, making descriptions per-class and not instance!
3280    evas_object_smart_callbacks_descriptions_set(obj, _signals);
3281
3282    if (!ecore_file_download_protocol_available("http://"))
3283      {
3284         ERR("Ecore must be built with curl support for the map widget!");
3285      }
3286
3287    return obj;
3288 #else
3289    (void) parent;
3290    return NULL;
3291 #endif
3292 }
3293
3294 EAPI void
3295 elm_map_zoom_set(Evas_Object *obj, int zoom)
3296 {
3297 #ifdef HAVE_ELEMENTARY_ECORE_CON
3298    ELM_CHECK_WIDTYPE(obj, widtype);
3299    Widget_Data *wd = elm_widget_data_get(obj);
3300    Eina_List *l;
3301    Grid *g, *g_zoom = NULL;
3302    Evas_Coord rx, ry, rw, rh;
3303    Evas_Object *p;
3304    Elm_Map_Route *r;
3305    Evas_Object *route;
3306    int z = 0, zoom_changed = 0, started = 0;
3307
3308    if ((!wd) || (!wd->src) || (wd->zoom_animator)) return;
3309    if (zoom < 0 ) zoom = 0;
3310    if (zoom > wd->src->zoom_max) zoom = wd->src->zoom_max;
3311    if (zoom < wd->src->zoom_min) zoom = wd->src->zoom_min;
3312
3313    if ((wd->zoom - zoom) > 0) wd->zoom_method = ZOOM_METHOD_OUT;
3314    else if ((wd->zoom - zoom) < 0) wd->zoom_method = ZOOM_METHOD_IN;
3315    else wd->zoom_method = ZOOM_METHOD_NONE;
3316    if (wd->zoom != zoom ) zoom_changed = 1;
3317    wd->zoom = zoom;
3318    wd->size.ow = wd->size.w;
3319    wd->size.oh = wd->size.h;
3320    elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
3321    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3322
3323    EINA_LIST_FOREACH(wd->route, l, r)
3324      {
3325         if (r)
3326           {
3327              EINA_LIST_FOREACH(r->path, l, p)
3328                {
3329                   evas_object_polygon_points_clear(p);
3330                }
3331           }
3332      }
3333
3334    EINA_LIST_FOREACH(wd->track, l, route)
3335      {
3336        evas_object_hide(route);
3337      }
3338
3339    if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3340      {
3341         int p2w, p2h;
3342         int cumulw, cumulh;
3343
3344         cumulw = wd->tsize;
3345         p2w = 0;
3346         while (cumulw <= rw)
3347           {
3348              p2w++;
3349              cumulw *= 2;
3350           }
3351         p2w--;
3352
3353         cumulh = wd->tsize;
3354         p2h = 0;
3355         while (cumulh <= rh)
3356           {
3357              p2h++;
3358              cumulh *= 2;
3359           }
3360         p2h--;
3361
3362         if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FIT)
3363           {
3364              if (p2w < p2h) z = p2w;
3365              else z = p2h;
3366           }
3367         else if (wd->mode == ELM_MAP_ZOOM_MODE_AUTO_FILL)
3368           {
3369              if (p2w > p2h) z = p2w;
3370              else z = p2h;
3371           }
3372         wd->zoom = z;
3373      }
3374    wd->size.nw = pow(2.0, wd->zoom) * wd->tsize;
3375    wd->size.nh = pow(2.0, wd->zoom) * wd->tsize;
3376
3377    g = grid_create(obj);
3378    if (g)
3379      {
3380         if (eina_list_count(wd->grids) > 1)
3381           {
3382              g_zoom = eina_list_last(wd->grids)->data;
3383              wd->grids = eina_list_remove(wd->grids, g_zoom);
3384              grid_clear(obj, g_zoom);
3385              free(g_zoom);
3386           }
3387         wd->grids = eina_list_prepend(wd->grids, g);
3388      }
3389    else
3390      {
3391         EINA_LIST_FREE(wd->grids, g)
3392           {
3393              grid_clear(obj, g);
3394              free(g);
3395           }
3396      }
3397
3398    wd->t = 1.0;
3399    if ((wd->size.w > 0) && (wd->size.h > 0))
3400      {
3401         wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.ow;
3402         wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.oh;
3403      }
3404    else
3405      {
3406         wd->size.spos.x = 0.5;
3407         wd->size.spos.y = 0.5;
3408      }
3409
3410    if (rw > wd->size.ow) wd->size.spos.x = 0.5;
3411    if (rh > wd->size.oh) wd->size.spos.y = 0.5;
3412    if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
3413    if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
3414
3415    if (wd->paused)
3416      {
3417         zoom_do(obj);
3418         if (wd->calc_job) ecore_job_del(wd->calc_job);
3419         wd->calc_job = ecore_job_add(_calc_job, wd);
3420      }
3421    else
3422      {
3423         if (!wd->zoom_animator)
3424           {
3425              wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
3426              wd->nosmooth++;
3427              if (wd->nosmooth == 1) _smooth_update(obj);
3428              started = 1;
3429           }
3430      }
3431
3432    if (!wd->paused)
3433      {
3434         if (started) evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
3435         if (!wd->zoom_animator) evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3436      }
3437
3438    if (zoom_changed) evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
3439 #else
3440    (void) obj;
3441    (void) zoom;
3442 #endif
3443 }
3444
3445 EAPI int
3446 elm_map_zoom_get(const Evas_Object *obj)
3447 {
3448 #ifdef HAVE_ELEMENTARY_ECORE_CON
3449    ELM_CHECK_WIDTYPE(obj, widtype) 0;
3450    Widget_Data *wd = elm_widget_data_get(obj);
3451
3452    if (!wd) return 0;
3453    return wd->zoom;
3454 #else
3455    (void) obj;
3456    return 0;
3457 #endif
3458 }
3459
3460 EAPI void
3461 elm_map_zoom_mode_set(Evas_Object *obj, Elm_Map_Zoom_Mode mode)
3462 {
3463 #ifdef HAVE_ELEMENTARY_ECORE_CON
3464    ELM_CHECK_WIDTYPE(obj, widtype);
3465    Widget_Data *wd = elm_widget_data_get(obj);
3466
3467    if (!wd) return;
3468    if (wd->mode == mode) return;
3469    wd->mode = mode;
3470
3471    if (wd->mode != ELM_MAP_ZOOM_MODE_MANUAL)
3472      {
3473         int tz = wd->zoom;
3474         wd->zoom = 0;
3475         elm_map_zoom_set(wd->obj, tz);
3476      }
3477 #else
3478    (void) obj;
3479    (void) mode;
3480 #endif
3481 }
3482
3483 EAPI Elm_Map_Zoom_Mode
3484 elm_map_zoom_mode_get(const Evas_Object *obj)
3485 {
3486 #ifdef HAVE_ELEMENTARY_ECORE_CON
3487    ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ZOOM_MODE_MANUAL;
3488    Widget_Data *wd = elm_widget_data_get(obj);
3489
3490    if (!wd) return ELM_MAP_ZOOM_MODE_MANUAL;
3491    return wd->mode;
3492 #else
3493    (void) obj;
3494    return ELM_MAP_ZOOM_MODE_MANUAL;
3495 #endif
3496 }
3497
3498 EAPI void
3499 elm_map_geo_region_bring_in(Evas_Object *obj, double lon, double lat)
3500 {
3501 #ifdef HAVE_ELEMENTARY_ECORE_CON
3502    ELM_CHECK_WIDTYPE(obj, widtype);
3503    Widget_Data *wd = elm_widget_data_get(obj);
3504    int rx, ry, rw, rh;
3505
3506    if (!wd) return;
3507    elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
3508    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3509
3510    rx = rx - rw / 2;
3511    ry = ry - rh / 2;
3512
3513    if (wd->zoom_animator)
3514      {
3515         wd->nosmooth--;
3516         if (!wd->nosmooth) _smooth_update(obj);
3517         ecore_animator_del(wd->zoom_animator);
3518         wd->zoom_animator = NULL;
3519         zoom_do(obj);
3520         evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3521      }
3522    elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
3523
3524    wd->center_on.enabled = EINA_TRUE;
3525    wd->center_on.lon = lon;
3526    wd->center_on.lat = lat;
3527 #else
3528    (void) obj;
3529    (void) lon;
3530    (void) lat;
3531 #endif
3532 }
3533
3534 EAPI void
3535 elm_map_geo_region_show(Evas_Object *obj, double lon, double lat)
3536 {
3537 #ifdef HAVE_ELEMENTARY_ECORE_CON
3538    ELM_CHECK_WIDTYPE(obj, widtype);
3539    Widget_Data *wd = elm_widget_data_get(obj);
3540    int rx, ry, rw, rh;
3541
3542    if (!wd) return;
3543    elm_map_utils_convert_geo_into_coord(obj, lon, lat, wd->size.w, &rx, &ry);
3544    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
3545
3546    rx = rx - rw / 2;
3547    ry = ry - rh / 2;
3548
3549    if (wd->zoom_animator)
3550      {
3551         wd->nosmooth--;
3552         ecore_animator_del(wd->zoom_animator);
3553         wd->zoom_animator = NULL;
3554         zoom_do(obj);
3555         evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3556      }
3557    elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
3558
3559    wd->center_on.enabled = EINA_TRUE;
3560    wd->center_on.lon = lon;
3561    wd->center_on.lat = lat;
3562 #else
3563    (void) obj;
3564    (void) lon;
3565    (void) lat;
3566 #endif
3567 }
3568
3569 EAPI void
3570 elm_map_geo_region_get(const Evas_Object *obj, double *lon, double *lat)
3571 {
3572 #ifdef HAVE_ELEMENTARY_ECORE_CON
3573    ELM_CHECK_WIDTYPE(obj, widtype);
3574    Widget_Data *wd = elm_widget_data_get(obj);
3575    Evas_Coord sx, sy, sw, sh;
3576
3577    if (!wd) return;
3578    elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
3579    elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
3580    sx += sw / 2;
3581    sy += sh / 2;
3582
3583    elm_map_utils_convert_coord_into_geo(obj, sx, sy, wd->size.w, lon, lat);
3584 #else
3585    (void) obj;
3586    (void) lon;
3587    (void) lat;
3588 #endif
3589 }
3590
3591 EAPI void
3592 elm_map_paused_set(Evas_Object *obj, Eina_Bool paused)
3593 {
3594 #ifdef HAVE_ELEMENTARY_ECORE_CON
3595    ELM_CHECK_WIDTYPE(obj, widtype);
3596    Widget_Data *wd = elm_widget_data_get(obj);
3597
3598    if (!wd) return;
3599    if (wd->paused == !!paused) return;
3600    wd->paused = paused;
3601    if (wd->paused)
3602      {
3603         if (wd->zoom_animator)
3604           {
3605              if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
3606              wd->zoom_animator = NULL;
3607              zoom_do(obj);
3608              evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
3609           }
3610      }
3611 #else
3612    (void) obj;
3613    (void) paused;
3614 #endif
3615 }
3616
3617 EAPI void
3618 elm_map_paused_markers_set(Evas_Object *obj, Eina_Bool paused)
3619 {
3620 #ifdef HAVE_ELEMENTARY_ECORE_CON
3621    ELM_CHECK_WIDTYPE(obj, widtype);
3622    Widget_Data *wd = elm_widget_data_get(obj);
3623
3624    if (!wd) return;
3625    if (wd->paused_markers == !!paused) return;
3626    wd->paused_markers = paused;
3627 #else
3628    (void) obj;
3629    (void) paused;
3630 #endif
3631 }
3632
3633 EAPI Eina_Bool
3634 elm_map_paused_get(const Evas_Object *obj)
3635 {
3636 #ifdef HAVE_ELEMENTARY_ECORE_CON
3637    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3638    Widget_Data *wd = elm_widget_data_get(obj);
3639
3640    if (!wd) return EINA_FALSE;
3641    return wd->paused;
3642 #else
3643    (void) obj;
3644    return EINA_FALSE;
3645 #endif
3646 }
3647
3648 EAPI Eina_Bool
3649 elm_map_paused_markers_get(const Evas_Object *obj)
3650 {
3651 #ifdef HAVE_ELEMENTARY_ECORE_CON
3652    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3653    Widget_Data *wd = elm_widget_data_get(obj);
3654
3655    if (!wd) return EINA_FALSE;
3656    return wd->paused_markers;
3657 #else
3658    (void) obj;
3659    return EINA_FALSE;
3660 #endif
3661 }
3662
3663 EAPI void
3664 elm_map_utils_downloading_status_get(const Evas_Object *obj, int *try_num, int *finish_num)
3665 {
3666 #ifdef HAVE_ELEMENTARY_ECORE_CON
3667    ELM_CHECK_WIDTYPE(obj, widtype);
3668    Widget_Data *wd = elm_widget_data_get(obj);
3669
3670    if (!wd) return;
3671    if (try_num)
3672      {
3673         *try_num = wd->try_num;
3674      }
3675
3676    if (finish_num)
3677      {
3678         *finish_num = wd->finish_num;
3679      }
3680 #else
3681    (void) obj;
3682    (void) try_num;
3683    (void) finish_num;
3684 #endif
3685 }
3686
3687 EAPI void
3688 elm_map_utils_convert_coord_into_geo(const Evas_Object *obj, int x, int y, int size, double *lon, double *lat)
3689 {
3690 #ifdef HAVE_ELEMENTARY_ECORE_CON
3691    ELM_CHECK_WIDTYPE(obj, widtype);
3692    Widget_Data *wd = elm_widget_data_get(obj);
3693
3694    if (!wd) return;
3695    int zoom = floor(log(size / 256) / log(2));
3696    if ((wd->src) && (wd->src->coord_into_geo))
3697      {
3698         if (wd->src->coord_into_geo(obj, zoom, x, y, size, lon, lat)) return;
3699      }
3700
3701    if (lon)
3702      {
3703         *lon = x / (double)size * 360.0 - 180;
3704      }
3705    if (lat)
3706      {
3707         double n = ELM_PI - 2.0 * ELM_PI * y / size;
3708         *lat = 180.0 / ELM_PI * atan(0.5 * (exp(n) - exp(-n)));
3709      }
3710 #else
3711    (void) obj;
3712    (void) x;
3713    (void) y;
3714    (void) size;
3715    (void) lon;
3716    (void) lat;
3717 #endif
3718 }
3719
3720 EAPI void
3721 elm_map_utils_convert_geo_into_coord(const Evas_Object *obj, double lon, double lat, int size, int *x, int *y)
3722 {
3723 #ifdef HAVE_ELEMENTARY_ECORE_CON
3724    ELM_CHECK_WIDTYPE(obj, widtype);
3725    Widget_Data *wd = elm_widget_data_get(obj);
3726
3727    if (!wd) return;
3728    int zoom = floor(log(size / 256) / log(2));
3729    if ((wd->src) && (wd->src->geo_into_coord))
3730      {
3731         if (wd->src->geo_into_coord(obj, zoom, lon, lat, size, x, y)) return;
3732      }
3733
3734    if (x)
3735      *x = floor((lon + 180.0) / 360.0 * size);
3736    if (y)
3737      *y = floor((1.0 - log( tan(lat * ELM_PI / 180.0) + 1.0 / cos(lat * ELM_PI / 180.0)) / ELM_PI) / 2.0 * size);
3738 #else
3739    (void) obj;
3740    (void) lon;
3741    (void) lat;
3742    (void) size;
3743    (void) x;
3744    (void) y;
3745 #endif
3746 }
3747
3748 EAPI Elm_Map_Name *
3749 elm_map_utils_convert_coord_into_name(const Evas_Object *obj, double lon, double lat)
3750 {
3751 #ifdef HAVE_ELEMENTARY_ECORE_CON
3752    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3753    return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_REVERSE, NULL, lon, lat);
3754 #else
3755    (void) obj;
3756    (void) lon;
3757    (void) lat;
3758    return NULL;
3759 #endif
3760 }
3761
3762 EAPI Elm_Map_Name *
3763 elm_map_utils_convert_name_into_coord(const Evas_Object *obj, char *address)
3764 {
3765 #ifdef HAVE_ELEMENTARY_ECORE_CON
3766    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3767    if (!address) return NULL;
3768    return _utils_convert_name(obj, ELM_MAP_NAME_METHOD_SEARCH, address, 0.0, 0.0);
3769 #else
3770    (void) obj;
3771    (void) address;
3772    return NULL;
3773 #endif
3774 }
3775
3776 EAPI void
3777 elm_map_utils_rotate_coord(const Evas_Object *obj __UNUSED__, const Evas_Coord x, const Evas_Coord y, const Evas_Coord cx, const Evas_Coord cy, const double degree, Evas_Coord *xx, Evas_Coord *yy)
3778 {
3779 #ifdef HAVE_ELEMENTARY_ECORE_CON
3780    if ((!xx) || (!yy)) return;
3781
3782    double r = (degree * M_PI) / 180.0;
3783    double tx, ty, ttx, tty;
3784
3785    tx = x - cx;
3786    ty = y - cy;
3787
3788    ttx = tx * cos(r);
3789    tty = tx * sin(r);
3790    tx = ttx + (ty * cos(r + M_PI_2));
3791    ty = tty + (ty * sin(r + M_PI_2));
3792
3793    *xx = tx + cx;
3794    *yy = ty + cy;
3795 #else
3796    (void) x;
3797    (void) y;
3798    (void) cx;
3799    (void) cy;
3800    (void) degree;
3801    (void) xx;
3802    (void) yy;
3803 #endif
3804 }
3805
3806 EAPI Elm_Map_Marker *
3807 elm_map_marker_add(Evas_Object *obj, double lon, double lat, Elm_Map_Marker_Class *clas, Elm_Map_Group_Class *clas_group, void *data)
3808 {
3809 #ifdef HAVE_ELEMENTARY_ECORE_CON
3810    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3811    Widget_Data *wd = elm_widget_data_get(obj);
3812    int i, j;
3813    Eina_List *l;
3814    Marker_Group *group;
3815    int mpi, mpj;
3816    int tabi[9];
3817    int tabj[9];
3818    const char *s;
3819    const char *style;
3820    Evas_Object *o;
3821
3822    if (!wd) return NULL;
3823    EINA_SAFETY_ON_NULL_RETURN_VAL(clas_group, NULL);
3824    EINA_SAFETY_ON_NULL_RETURN_VAL(clas, NULL);
3825
3826    Elm_Map_Marker *marker = ELM_NEW(Elm_Map_Marker);
3827
3828    marker->wd = wd;
3829    marker->clas = clas;
3830    marker->clas_group = clas_group;
3831    marker->longitude = lon;
3832    marker->latitude = lat;
3833    marker->data = data;
3834    marker->x = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
3835    marker->y = calloc(wd->zoom_max + 1, sizeof(Evas_Coord));
3836    marker->groups = calloc(wd->zoom_max + 1, sizeof(Marker_Group*));
3837
3838    tabi[1] = tabi[4] = tabi[6] = -1;
3839    tabi[2] = tabi[0] = tabi[7] = 0;
3840    tabi[3] = tabi[5] = tabi[8] = 1;
3841
3842    tabj[1] = tabj[2] = tabj[3] = -1;
3843    tabj[4] = tabj[0] = tabj[5] = 0;
3844    tabj[6] = tabj[7] = tabj[8] = 1;
3845
3846    if (!clas_group->priv.set)
3847      {
3848         style = "radio";
3849         if (marker->clas_group && marker->clas_group->style)
3850           style = marker->clas_group->style;
3851
3852         o = edje_object_add(evas_object_evas_get(obj));
3853         _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
3854         s = edje_object_data_get(o, "size_w");
3855         if (s) clas_group->priv.edje_w = atoi(s);
3856         else clas_group->priv.edje_w = 0;
3857         s = edje_object_data_get(o, "size_h");
3858         if (s) clas_group->priv.edje_h = atoi(s);
3859         else clas_group->priv.edje_h = 0;
3860         s = edje_object_data_get(o, "size_max_w");
3861         if (s) clas_group->priv.edje_max_w = atoi(s);
3862         else clas_group->priv.edje_max_w = 0;
3863         s = edje_object_data_get(o, "size_max_h");
3864         if (s) clas_group->priv.edje_max_h = atoi(s);
3865         else clas_group->priv.edje_max_h = 0;
3866         evas_object_del(o);
3867
3868         clas_group->priv.set = EINA_TRUE;
3869      }
3870
3871    if (!clas->priv.set)
3872      {
3873         style = "radio";
3874         if (marker->clas && marker->clas->style)
3875           style = marker->clas->style;
3876
3877         o = edje_object_add(evas_object_evas_get(obj));
3878         _elm_theme_object_set(obj, o, "map/marker", style, elm_widget_style_get(obj));
3879         s = edje_object_data_get(o, "size_w");
3880         if (s) clas->priv.edje_w = atoi(s);
3881         else clas->priv.edje_w = 0;
3882         s = edje_object_data_get(o, "size_h");
3883         if (s) clas->priv.edje_h = atoi(s);
3884         else clas->priv.edje_h = 0;
3885         evas_object_del(o);
3886
3887         clas->priv.set = EINA_TRUE;
3888      }
3889
3890    for (i = clas_group->zoom_displayed; i <= wd->zoom_max; i++)
3891      {
3892         elm_map_utils_convert_geo_into_coord(obj, lon, lat, pow(2.0, i)*wd->tsize,
3893                                              &(marker->x[i]), &(marker->y[i]));
3894
3895         //search in the matrixsparse the region where the marker will be
3896         mpi = marker->x[i] / wd->tsize;
3897         mpj = marker->y[i] / wd->tsize;
3898
3899         if (!wd->markers[i])
3900           {
3901              int size =  pow(2.0, i);
3902              wd->markers[i] = eina_matrixsparse_new(size, size, NULL, NULL);
3903           }
3904
3905         group = NULL;
3906         if (i <= clas_group->zoom_grouped)
3907           {
3908              for (j = 0, group = NULL; j < 9 && !group; j++)
3909                {
3910                   EINA_LIST_FOREACH(eina_matrixsparse_data_idx_get(wd->markers[i], mpj + tabj[j], mpi + tabi[j]),
3911                                     l, group)
3912                     {
3913                        if (group->clas == marker->clas_group
3914                            && ELM_RECTS_INTERSECT(marker->x[i]-clas->priv.edje_w/4,
3915                                                   marker->y[i]-clas->priv.edje_h/4, clas->priv.edje_w, clas->priv.edje_h,
3916                                                   group->x-group->w/4, group->y-group->h/4, group->w, group->h))
3917                          {
3918                             group->markers = eina_list_append(group->markers, marker);
3919                             group->update_nbelems = EINA_TRUE;
3920                             group->update_resize = EINA_TRUE;
3921
3922                             group->sum_x += marker->x[i];
3923                             group->sum_y += marker->y[i];
3924                             group->x = group->sum_x / eina_list_count(group->markers);
3925                             group->y = group->sum_y / eina_list_count(group->markers);
3926
3927                             group->w = group->clas->priv.edje_w + group->clas->priv.edje_w/8.
3928                                * eina_list_count(group->markers);
3929                             group->h = group->clas->priv.edje_h + group->clas->priv.edje_h/8.
3930                                * eina_list_count(group->markers);
3931                             if (group->w > group->clas->priv.edje_max_w) group->w = group->clas->priv.edje_max_w;
3932                             if (group->h > group->clas->priv.edje_max_h) group->h = group->clas->priv.edje_max_h;
3933
3934                             if (group->obj && eina_list_count(group->markers) == 2)
3935                               {
3936                                  _group_object_free(group);
3937                                  _group_object_create(group);
3938                               }
3939                             if (group->bubble)
3940                               _group_bubble_content_update(group);
3941
3942                             break;
3943                          }
3944                     }
3945                }
3946           }
3947         if (!group)
3948           {
3949              group = calloc(1, sizeof(Marker_Group));
3950              group->wd = wd;
3951              group->sum_x = marker->x[i];
3952              group->sum_y = marker->y[i];
3953              group->x = marker->x[i];
3954              group->y = marker->y[i];
3955              group->w = clas_group->priv.edje_w;
3956              group->h = clas_group->priv.edje_h;
3957              group->clas = clas_group;
3958
3959              group->markers = eina_list_append(group->markers, marker);
3960              group->update_nbelems = EINA_TRUE;
3961              group->update_resize = EINA_TRUE;
3962
3963              eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
3964
3965              if (!group->cell)
3966                {
3967                   l = eina_list_append(NULL, group);
3968                   eina_matrixsparse_data_idx_set(wd->markers[i], mpj, mpi, l);
3969                   eina_matrixsparse_cell_idx_get(wd->markers[i], mpj, mpi, &(group->cell));
3970                }
3971              else
3972                {
3973                   l = eina_matrixsparse_cell_data_get(group->cell);
3974                   l = eina_list_append(l, group);
3975                   eina_matrixsparse_cell_data_set(group->cell, l);
3976                }
3977           }
3978         marker->groups[i] = group;
3979      }
3980
3981    if (wd->grids)
3982      {
3983         Evas_Coord ox, oy, ow, oh;
3984         evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
3985         marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
3986      }
3987
3988    return marker;
3989 #else
3990    (void) obj;
3991    (void) lon;
3992    (void) lat;
3993    (void) clas;
3994    (void) clas_group;
3995    (void) data;
3996    return NULL;
3997 #endif
3998 }
3999
4000 EAPI void
4001 elm_map_marker_remove(Elm_Map_Marker *marker)
4002 {
4003 #ifdef HAVE_ELEMENTARY_ECORE_CON
4004    int i;
4005    Eina_List *groups;
4006    Widget_Data *wd;
4007
4008    EINA_SAFETY_ON_NULL_RETURN(marker);
4009    wd = marker->wd;
4010    if (!wd) return;
4011    for (i = marker->clas_group->zoom_displayed; i <= wd->zoom_max; i++)
4012      {
4013         marker->groups[i]->markers = eina_list_remove(marker->groups[i]->markers, marker);
4014         if (!eina_list_count(marker->groups[i]->markers))
4015           {
4016              groups = eina_matrixsparse_cell_data_get(marker->groups[i]->cell);
4017              groups = eina_list_remove(groups, marker->groups[i]);
4018              eina_matrixsparse_cell_data_set(marker->groups[i]->cell, groups);
4019
4020              _group_object_free(marker->groups[i]);
4021              _group_bubble_free(marker->groups[i]);
4022              free(marker->groups[i]);
4023           }
4024         else
4025           {
4026              marker->groups[i]->sum_x -= marker->x[i];
4027              marker->groups[i]->sum_y -= marker->y[i];
4028
4029              marker->groups[i]->x = marker->groups[i]->sum_x / eina_list_count(marker->groups[i]->markers);
4030              marker->groups[i]->y = marker->groups[i]->sum_y / eina_list_count(marker->groups[i]->markers);
4031
4032              marker->groups[i]->w = marker->groups[i]->clas->priv.edje_w
4033                 + marker->groups[i]->clas->priv.edje_w/8. * eina_list_count(marker->groups[i]->markers);
4034              marker->groups[i]->h = marker->groups[i]->clas->priv.edje_h
4035                 + marker->groups[i]->clas->priv.edje_h/8. * eina_list_count(marker->groups[i]->markers);
4036              if (marker->groups[i]->w > marker->groups[i]->clas->priv.edje_max_w)
4037                marker->groups[i]->w = marker->groups[i]->clas->priv.edje_max_w;
4038              if (marker->groups[i]->h > marker->groups[i]->clas->priv.edje_max_h)
4039                marker->groups[i]->h = marker->groups[i]->clas->priv.edje_max_h;
4040
4041              if ((marker->groups[i]->obj) && (eina_list_count(marker->groups[i]->markers) == 1))
4042                {
4043                   _group_object_free(marker->groups[i]);
4044                   _group_object_create(marker->groups[i]);
4045                }
4046           }
4047      }
4048
4049    if ((marker->content) && (marker->clas->func.del))
4050      marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
4051    else if (marker->content)
4052      evas_object_del(marker->content);
4053
4054    if (marker->x) free(marker->x);
4055    if (marker->y) free(marker->y);
4056    if (marker->groups) free(marker->groups);
4057
4058    free(marker);
4059
4060    if (wd->grids)
4061      {
4062         Evas_Coord ox, oy, ow, oh;
4063         evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
4064         marker_place(wd->obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4065      }
4066 #else
4067    (void) marker;
4068 #endif
4069 }
4070
4071 EAPI void
4072 elm_map_marker_region_get(const Elm_Map_Marker *marker, double *lon, double *lat)
4073 {
4074 #ifdef HAVE_ELEMENTARY_ECORE_CON
4075    EINA_SAFETY_ON_NULL_RETURN(marker);
4076    if (lon) *lon = marker->longitude;
4077    if (lat) *lat = marker->latitude;
4078 #else
4079    (void) marker;
4080    (void) lon;
4081    (void) lat;
4082 #endif
4083 }
4084
4085 EAPI void
4086 elm_map_marker_bring_in(Elm_Map_Marker *marker)
4087 {
4088 #ifdef HAVE_ELEMENTARY_ECORE_CON
4089    EINA_SAFETY_ON_NULL_RETURN(marker);
4090    elm_map_geo_region_bring_in(marker->wd->obj, marker->longitude, marker->latitude);
4091 #else
4092    (void) marker;
4093 #endif
4094 }
4095
4096 EAPI void
4097 elm_map_marker_show(Elm_Map_Marker *marker)
4098 {
4099 #ifdef HAVE_ELEMENTARY_ECORE_CON
4100    EINA_SAFETY_ON_NULL_RETURN(marker);
4101    elm_map_geo_region_show(marker->wd->obj, marker->longitude, marker->latitude);
4102 #else
4103    (void) marker;
4104 #endif
4105 }
4106
4107 EAPI void
4108 elm_map_markers_list_show(Eina_List *markers)
4109 {
4110 #ifdef HAVE_ELEMENTARY_ECORE_CON
4111    int zoom;
4112    double lon, lat;
4113    Eina_List *l;
4114    Elm_Map_Marker *marker, *m_max_lon = NULL, *m_max_lat = NULL, *m_min_lon = NULL, *m_min_lat = NULL;
4115    Evas_Coord rw, rh, xc, yc;
4116    Widget_Data *wd;
4117
4118    EINA_SAFETY_ON_NULL_RETURN(markers);
4119    EINA_LIST_FOREACH(markers, l, marker)
4120      {
4121         wd = marker->wd;
4122
4123         if ((!m_min_lon) || (marker->longitude < m_min_lon->longitude))
4124           m_min_lon = marker;
4125
4126         if ((!m_max_lon) || (marker->longitude > m_max_lon->longitude))
4127           m_max_lon = marker;
4128
4129         if ((!m_min_lat) || (marker->latitude > m_min_lat->latitude))
4130           m_min_lat = marker;
4131
4132         if ((!m_max_lat) || (marker->latitude < m_max_lat->latitude))
4133           m_max_lat = marker;
4134      }
4135
4136    lon = (m_max_lon->longitude - m_min_lon->longitude) / 2. + m_min_lon->longitude;
4137    lat = (m_max_lat->latitude - m_min_lat->latitude) / 2. + m_min_lat->latitude;
4138
4139    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
4140    for (zoom = wd->src->zoom_max; zoom > wd->src->zoom_min; zoom--)
4141      {
4142         Evas_Coord size = pow(2.0, zoom)*wd->tsize;
4143         elm_map_utils_convert_geo_into_coord(wd->obj, lon, lat, size, &xc, &yc);
4144
4145         if ((m_min_lon->x[zoom] - wd->marker_max_w >= xc-rw/2)
4146             && (m_min_lat->y[zoom] - wd->marker_max_h >= yc-rh/2)
4147             && (m_max_lon->x[zoom] + wd->marker_max_w <= xc+rw/2)
4148             && (m_max_lat->y[zoom] + wd->marker_max_h <= yc+rh/2))
4149           break;
4150      }
4151
4152    elm_map_geo_region_show(wd->obj, lon, lat);
4153    elm_map_zoom_set(wd->obj, zoom);
4154 #else
4155    (void) markers;
4156 #endif
4157 }
4158
4159 EAPI void
4160 elm_map_max_marker_per_group_set(Evas_Object *obj, int max)
4161 {
4162 #ifdef HAVE_ELEMENTARY_ECORE_CON
4163    ELM_CHECK_WIDTYPE(obj, widtype);
4164    Widget_Data *wd = elm_widget_data_get(obj);
4165
4166    if (!wd) return;
4167    wd->markers_max_num = max;
4168 #else
4169    (void) obj;
4170    (void) max;
4171 #endif
4172 }
4173
4174 EAPI Evas_Object *
4175 elm_map_marker_object_get(const Elm_Map_Marker *marker)
4176 {
4177 #ifdef HAVE_ELEMENTARY_ECORE_CON
4178    EINA_SAFETY_ON_NULL_RETURN_VAL(marker, NULL);
4179    return marker->content;
4180 #else
4181    (void) marker;
4182    return NULL;
4183 #endif
4184 }
4185
4186 EAPI void
4187 elm_map_marker_update(Elm_Map_Marker *marker)
4188 {
4189 #ifdef HAVE_ELEMENTARY_ECORE_CON
4190    EINA_SAFETY_ON_NULL_RETURN(marker);
4191    if (marker->content)
4192      {
4193         if (marker->clas->func.del)
4194           marker->clas->func.del(marker->wd->obj, marker, marker->data, marker->content);
4195         else
4196           evas_object_del(marker->content);
4197         marker->content = NULL;
4198         _group_bubble_content_update(marker->groups[marker->wd->zoom]);
4199      }
4200 #else
4201    (void) marker;
4202 #endif
4203 }
4204
4205 EAPI void
4206 elm_map_bubbles_close(Evas_Object *obj)
4207 {
4208 #ifdef HAVE_ELEMENTARY_ECORE_CON
4209    ELM_CHECK_WIDTYPE(obj, widtype);
4210    Widget_Data *wd = elm_widget_data_get(obj);
4211    Marker_Group *group;
4212    Eina_List *l, *l_next;
4213
4214    if (!wd) return;
4215    EINA_LIST_FOREACH_SAFE(wd->opened_bubbles, l, l_next, group)
4216       _group_bubble_free(group);
4217 #else
4218    (void) obj;
4219 #endif
4220 }
4221
4222 EAPI Elm_Map_Group_Class *
4223 elm_map_group_class_new(Evas_Object *obj)
4224 {
4225 #ifdef HAVE_ELEMENTARY_ECORE_CON
4226    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4227    Widget_Data *wd = elm_widget_data_get(obj);
4228
4229    if (!wd) return NULL;
4230    Elm_Map_Group_Class *clas = calloc(1, sizeof(Elm_Map_Group_Class));
4231    clas->zoom_grouped = wd->zoom_max;
4232    wd->groups_clas = eina_list_append(wd->groups_clas, clas);
4233    return clas;
4234 #else
4235    (void) obj;
4236    return NULL;
4237 #endif
4238 }
4239
4240 EAPI void
4241 elm_map_group_class_style_set(Elm_Map_Group_Class *clas, const char *style)
4242 {
4243 #ifdef HAVE_ELEMENTARY_ECORE_CON
4244    EINA_SAFETY_ON_NULL_RETURN(clas);
4245    eina_stringshare_replace(&clas->style, style);
4246 #else
4247    (void) clas;
4248    (void) style;
4249 #endif
4250 }
4251
4252 EAPI void
4253 elm_map_group_class_icon_cb_set(Elm_Map_Group_Class *clas, ElmMapGroupIconGetFunc icon_get)
4254 {
4255 #ifdef HAVE_ELEMENTARY_ECORE_CON
4256    EINA_SAFETY_ON_NULL_RETURN(clas);
4257    clas->func.icon_get = icon_get;
4258 #else
4259    (void) clas;
4260    (void) icon_get;
4261 #endif
4262 }
4263
4264 EAPI void
4265 elm_map_group_class_data_set(Elm_Map_Group_Class *clas, void *data)
4266 {
4267 #ifdef HAVE_ELEMENTARY_ECORE_CON
4268    EINA_SAFETY_ON_NULL_RETURN(clas);
4269    clas->data = data;
4270 #else
4271    (void) clas;
4272    (void) data;
4273 #endif
4274 }
4275
4276 EAPI void
4277 elm_map_group_class_zoom_displayed_set(Elm_Map_Group_Class *clas, int zoom)
4278 {
4279 #ifdef HAVE_ELEMENTARY_ECORE_CON
4280    EINA_SAFETY_ON_NULL_RETURN(clas);
4281    clas->zoom_displayed = zoom;
4282 #else
4283    (void) clas;
4284    (void) zoom;
4285 #endif
4286 }
4287
4288 EAPI void
4289 elm_map_group_class_zoom_grouped_set(Elm_Map_Group_Class *clas, int zoom)
4290 {
4291 #ifdef HAVE_ELEMENTARY_ECORE_CON
4292    EINA_SAFETY_ON_NULL_RETURN(clas);
4293    clas->zoom_grouped = zoom;
4294 #else
4295    (void) clas;
4296    (void) zoom;
4297 #endif
4298 }
4299
4300 EAPI void
4301 elm_map_group_class_hide_set(Evas_Object *obj, Elm_Map_Group_Class *clas, Eina_Bool hide)
4302 {
4303 #ifdef HAVE_ELEMENTARY_ECORE_CON
4304    ELM_CHECK_WIDTYPE(obj, widtype);
4305    Widget_Data *wd = elm_widget_data_get(obj);
4306
4307    if (!wd) return;
4308    EINA_SAFETY_ON_NULL_RETURN(clas);
4309    if (clas->hide == hide) return;
4310    clas->hide = hide;
4311    if (wd->grids)
4312      {
4313         Evas_Coord ox, oy, ow, oh;
4314         evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
4315         marker_place(obj, eina_list_data_get(wd->grids), wd->pan_x, wd->pan_y, ox, oy, ow, oh);
4316      }
4317 #else
4318    (void) obj;
4319    (void) clas;
4320    (void) hide;
4321 #endif
4322 }
4323
4324 EAPI Elm_Map_Marker_Class *
4325 elm_map_marker_class_new(Evas_Object *obj)
4326 {
4327 #ifdef HAVE_ELEMENTARY_ECORE_CON
4328    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4329    Widget_Data *wd = elm_widget_data_get(obj);
4330
4331    if (!wd) return NULL;
4332    Elm_Map_Marker_Class *clas = calloc(1, sizeof(Elm_Map_Marker_Class));
4333    wd->markers_clas = eina_list_append(wd->markers_clas, clas);
4334    return clas;
4335 #else
4336    (void) obj;
4337    return NULL;
4338 #endif
4339 }
4340
4341 EAPI void
4342 elm_map_marker_class_style_set(Elm_Map_Marker_Class *clas, const char *style)
4343 {
4344 #ifdef HAVE_ELEMENTARY_ECORE_CON
4345    EINA_SAFETY_ON_NULL_RETURN(clas);
4346    eina_stringshare_replace(&clas->style, style);
4347 #else
4348    (void) clas;
4349    (void) style;
4350 #endif
4351 }
4352
4353 EAPI void
4354 elm_map_marker_class_icon_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerIconGetFunc icon_get)
4355 {
4356 #ifdef HAVE_ELEMENTARY_ECORE_CON
4357    EINA_SAFETY_ON_NULL_RETURN(clas);
4358    clas->func.icon_get = icon_get;
4359 #else
4360    (void) clas;
4361    (void) icon_get;
4362 #endif
4363 }
4364
4365 EAPI void
4366 elm_map_marker_class_get_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerGetFunc get)
4367 {
4368 #ifdef HAVE_ELEMENTARY_ECORE_CON
4369    EINA_SAFETY_ON_NULL_RETURN(clas);
4370    clas->func.get = get;
4371 #else
4372    (void) clas;
4373    (void) get;
4374 #endif
4375 }
4376
4377 EAPI void
4378 elm_map_marker_class_del_cb_set(Elm_Map_Marker_Class *clas, ElmMapMarkerDelFunc del)
4379 {
4380 #ifdef HAVE_ELEMENTARY_ECORE_CON
4381    EINA_SAFETY_ON_NULL_RETURN(clas);
4382    clas->func.del = del;
4383 #else
4384    (void) clas;
4385    (void) del;
4386 #endif
4387 }
4388
4389 EAPI const char **
4390 elm_map_source_names_get(const Evas_Object *obj)
4391 {
4392 #ifdef HAVE_ELEMENTARY_ECORE_CON
4393    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4394    Widget_Data *wd = elm_widget_data_get(obj);
4395
4396    if (!wd) return NULL;
4397    return wd->source_names;
4398 #else
4399    (void) obj;
4400    return NULL;
4401 #endif
4402 }
4403
4404 EAPI void
4405 elm_map_source_name_set(Evas_Object *obj, const char *source_name)
4406 {
4407 #ifdef HAVE_ELEMENTARY_ECORE_CON
4408    ELM_CHECK_WIDTYPE(obj, widtype);
4409    Widget_Data *wd = elm_widget_data_get(obj);
4410    Map_Sources_Tab *s;
4411    Eina_List *l;
4412    Grid *grid;
4413    int zoom;
4414
4415    if (!wd) return;
4416    if (wd->src)
4417      {
4418         if (!strcmp(wd->src->name, source_name)) return;
4419         if (!wd->src->url_cb) return;
4420      }
4421
4422    EINA_LIST_FREE(wd->grids, grid) grid_clear(obj, grid);
4423    EINA_LIST_FOREACH(wd->map_sources_tab, l, s)
4424      {
4425         if (!strcmp(s->name, source_name))
4426           {
4427              wd->src = s;
4428              break;
4429           }
4430      }
4431    zoom = wd->zoom;
4432    wd->zoom = -1;
4433
4434    if (wd->src)
4435      {
4436         if (wd->src->zoom_max < zoom)
4437           zoom = wd->src->zoom_max;
4438         if (wd->src->zoom_min > zoom)
4439           zoom = wd->src->zoom_min;
4440      }
4441    elm_map_zoom_set(obj, zoom);
4442 #else
4443    (void) obj;
4444    (void) source_name;
4445 #endif
4446 }
4447
4448 EAPI const char *
4449 elm_map_source_name_get(const Evas_Object *obj)
4450 {
4451 #ifdef HAVE_ELEMENTARY_ECORE_CON
4452    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4453    Widget_Data *wd = elm_widget_data_get(obj);
4454
4455    if ((!wd) || (!wd->src)) return NULL;
4456    return wd->src->name;
4457 #else
4458    (void) obj;
4459    return NULL;
4460 #endif
4461 }
4462
4463 EAPI void
4464 elm_map_route_source_set(Evas_Object *obj, Elm_Map_Route_Sources source)
4465 {
4466 #ifdef HAVE_ELEMENTARY_ECORE_CON
4467    ELM_CHECK_WIDTYPE(obj, widtype);
4468    Widget_Data *wd = elm_widget_data_get(obj);
4469
4470    if (!wd) return;
4471    wd->route_source = source;
4472 #else
4473    (void) obj;
4474    (void) source;
4475 #endif
4476 }
4477
4478 EAPI Elm_Map_Route_Sources
4479 elm_map_route_source_get(const Evas_Object *obj)
4480 {
4481 #ifdef HAVE_ELEMENTARY_ECORE_CON
4482    ELM_CHECK_WIDTYPE(obj, widtype) ELM_MAP_ROUTE_SOURCE_YOURS;
4483    Widget_Data *wd = elm_widget_data_get(obj);
4484
4485    if (!wd) return ELM_MAP_ROUTE_SOURCE_YOURS;
4486    return wd->route_source;
4487 #else
4488    (void) obj;
4489    return ELM_MAP_ROUTE_SOURCE_YOURS;
4490 #endif
4491 }
4492
4493 EAPI void
4494 elm_map_source_zoom_max_set(Evas_Object *obj, int zoom)
4495 {
4496 #ifdef HAVE_ELEMENTARY_ECORE_CON
4497    ELM_CHECK_WIDTYPE(obj, widtype);
4498    Widget_Data *wd = elm_widget_data_get(obj);
4499
4500    if ((!wd) || (!wd->src)) return;
4501    if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
4502    wd->src->zoom_max = zoom;
4503 #else
4504    (void) obj;
4505    (void) zoom;
4506 #endif
4507 }
4508
4509 EAPI int
4510 elm_map_source_zoom_max_get(const Evas_Object *obj)
4511 {
4512 #ifdef HAVE_ELEMENTARY_ECORE_CON
4513    ELM_CHECK_WIDTYPE(obj, widtype) 18;
4514    Widget_Data *wd = elm_widget_data_get(obj);
4515
4516    if ((!wd) || (!wd->src)) return 18;
4517    return wd->src->zoom_max;
4518 #else
4519    (void) obj;
4520    return 18;
4521 #endif
4522 }
4523
4524 EAPI void
4525 elm_map_source_zoom_min_set(Evas_Object *obj, int zoom)
4526 {
4527 #ifdef HAVE_ELEMENTARY_ECORE_CON
4528    ELM_CHECK_WIDTYPE(obj, widtype);
4529    Widget_Data *wd = elm_widget_data_get(obj);
4530
4531    if ((!wd) || (!wd->src)) return;
4532    if ((zoom > wd->zoom_max) || (zoom < wd->zoom_min)) return;
4533    wd->src->zoom_min = zoom;
4534 #else
4535    (void) obj;
4536    (void) zoom;
4537 #endif
4538 }
4539
4540 EAPI int
4541 elm_map_source_zoom_min_get(const Evas_Object *obj)
4542 {
4543 #ifdef HAVE_ELEMENTARY_ECORE_CON
4544    ELM_CHECK_WIDTYPE(obj, widtype) 0;
4545    Widget_Data *wd = elm_widget_data_get(obj);
4546
4547    if ((!wd) || (!wd->src)) return 0;
4548    return wd->src->zoom_min;
4549 #else
4550    (void) obj;
4551    return 0;
4552 #endif
4553 }
4554
4555 EAPI void
4556 elm_map_user_agent_set(Evas_Object *obj, const char *user_agent)
4557 {
4558 #ifdef HAVE_ELEMENTARY_ECORE_CON
4559    ELM_CHECK_WIDTYPE(obj, widtype);
4560    Widget_Data *wd = elm_widget_data_get(obj);
4561
4562    if (!wd) return;
4563    if (!wd->user_agent) wd->user_agent = eina_stringshare_add(user_agent);
4564    else eina_stringshare_replace(&wd->user_agent, user_agent);
4565
4566    if (!wd->ua) wd->ua = eina_hash_string_small_new(NULL);
4567    eina_hash_set(wd->ua, "User-Agent", wd->user_agent);
4568 #else
4569    (void) obj;
4570    (void) user_agent;
4571 #endif
4572 }
4573
4574 EAPI const char *
4575 elm_map_user_agent_get(const Evas_Object *obj)
4576 {
4577 #ifdef HAVE_ELEMENTARY_ECORE_CON
4578    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4579    Widget_Data *wd = elm_widget_data_get(obj);
4580
4581    if (!wd) return NULL;
4582    return wd->user_agent;
4583 #else
4584    (void) obj;
4585    return NULL;
4586 #endif
4587 }
4588
4589 EAPI Elm_Map_Route *
4590 elm_map_route_add(Evas_Object *obj,
4591                   Elm_Map_Route_Type type,
4592                   Elm_Map_Route_Method method,
4593                   double flon,
4594                   double flat,
4595                   double tlon,
4596                   double tlat)
4597 {
4598 #ifdef HAVE_ELEMENTARY_ECORE_CON
4599    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4600    Widget_Data *wd = elm_widget_data_get(obj);
4601    char buf[PATH_MAX];
4602    char *source;
4603    char *type_name = NULL;
4604    int fd;
4605
4606    if ((!wd) || (!wd->src)) return NULL;
4607
4608    Elm_Map_Route *route = ELM_NEW(Elm_Map_Route);
4609    if (!route) return NULL;
4610
4611    snprintf(buf, sizeof(buf), DEST_ROUTE_XML_FILE);
4612    fd = mkstemp(buf);
4613    if (fd < 0)
4614      {
4615         free(route);
4616         return NULL;
4617      }
4618
4619    route->con_url = ecore_con_url_new(NULL);
4620    route->ud.fname = strdup(buf);
4621    INF("xml file : %s", route->ud.fname);
4622
4623    route->ud.fd = fdopen(fd, "w+");
4624    if ((!route->con_url) || (!route->ud.fd))
4625      {
4626         ecore_con_url_free(route->con_url);
4627         free(route);
4628         return NULL;
4629      }
4630
4631    route->wd = wd;
4632    route->color.r = 255;
4633    route->color.g = 0;
4634    route->color.b = 0;
4635    route->color.a = 255;
4636    route->handlers = eina_list_append
4637      (route->handlers, (void *)ecore_event_handler_add
4638          (ECORE_CON_EVENT_URL_COMPLETE, _route_complete_cb, route));
4639
4640    route->inbound = EINA_FALSE;
4641    route->type = type;
4642    route->method = method;
4643    route->flon = flon;
4644    route->flat = flat;
4645    route->tlon = tlon;
4646    route->tlat = tlat;
4647
4648    switch (type)
4649      {
4650       case ELM_MAP_ROUTE_TYPE_MOTOCAR:
4651         type_name = strdup(ROUTE_TYPE_MOTORCAR);
4652         break;
4653       case ELM_MAP_ROUTE_TYPE_BICYCLE:
4654         type_name = strdup(ROUTE_TYPE_BICYCLE);
4655         break;
4656       case ELM_MAP_ROUTE_TYPE_FOOT:
4657         type_name = strdup(ROUTE_TYPE_FOOT);
4658         break;
4659       default:
4660         break;
4661      }
4662
4663    source = wd->src->route_url_cb(obj, type_name, method, flon, flat, tlon, tlat);
4664    INF("route url = %s", source);
4665
4666    wd->route = eina_list_append(wd->route, route);
4667
4668    ecore_con_url_url_set(route->con_url, source);
4669    ecore_con_url_fd_set(route->con_url, fileno(route->ud.fd));
4670    ecore_con_url_data_set(route->con_url, route);
4671    ecore_con_url_get(route->con_url);
4672    if (type_name) free(type_name);
4673    if (source) free(source);
4674
4675    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
4676                            "elm,state,busy,start", "elm");
4677    evas_object_smart_callback_call(wd->obj, SIG_ROUTE_LOAD, NULL);
4678    return route;
4679 #else
4680    (void) obj;
4681    (void) type;
4682    (void) method;
4683    (void) flon;
4684    (void) flat;
4685    (void) tlon;
4686    (void) tlat;
4687    return NULL;
4688 #endif
4689 }
4690
4691 EAPI void
4692 elm_map_route_remove(Elm_Map_Route *route)
4693 {
4694 #ifdef HAVE_ELEMENTARY_ECORE_CON
4695    EINA_SAFETY_ON_NULL_RETURN(route);
4696
4697    Path_Waypoint *w;
4698    Path_Node *n;
4699    Evas_Object *p;
4700    Ecore_Event_Handler *h;
4701
4702    EINA_LIST_FREE(route->path, p)
4703      {
4704         evas_object_del(p);
4705      }
4706
4707    EINA_LIST_FREE(route->waypoint, w)
4708      {
4709         if (w->point) eina_stringshare_del(w->point);
4710         free(w);
4711      }
4712
4713    EINA_LIST_FREE(route->nodes, n)
4714      {
4715         if (n->pos.address) eina_stringshare_del(n->pos.address);
4716         free(n);
4717      }
4718
4719    EINA_LIST_FREE(route->handlers, h)
4720      {
4721         ecore_event_handler_del(h);
4722      }
4723
4724    if (route->ud.fname)
4725      {
4726         ecore_file_remove(route->ud.fname);
4727         free(route->ud.fname);
4728         route->ud.fname = NULL;
4729      }
4730 #else
4731    (void) route;
4732 #endif
4733 }
4734
4735 EAPI void
4736 elm_map_route_color_set(Elm_Map_Route *route, int r, int g , int b, int a)
4737 {
4738 #ifdef HAVE_ELEMENTARY_ECORE_CON
4739    EINA_SAFETY_ON_NULL_RETURN(route);
4740    route->color.r = r;
4741    route->color.g = g;
4742    route->color.b = b;
4743    route->color.a = a;
4744 #else
4745    (void) route;
4746    (void) r;
4747    (void) g;
4748    (void) b;
4749    (void) a;
4750 #endif
4751 }
4752
4753 EAPI void
4754 elm_map_route_color_get(const Elm_Map_Route *route, int *r, int *g , int *b, int *a)
4755 {
4756 #ifdef HAVE_ELEMENTARY_ECORE_CON
4757    EINA_SAFETY_ON_NULL_RETURN(route);
4758    if (r) *r = route->color.r;
4759    if (g) *g = route->color.g;
4760    if (b) *b = route->color.b;
4761    if (a) *a = route->color.a;
4762 #else
4763    (void) route;
4764    (void) r;
4765    (void) g;
4766    (void) b;
4767    (void) a;
4768 #endif
4769 }
4770
4771 EAPI double
4772 elm_map_route_distance_get(const Elm_Map_Route *route)
4773 {
4774 #ifdef HAVE_ELEMENTARY_ECORE_CON
4775    EINA_SAFETY_ON_NULL_RETURN_VAL(route, 0.0);
4776    return route->info.distance;
4777 #else
4778    (void) route;
4779    return 0.0;
4780 #endif
4781 }
4782
4783 EAPI const char*
4784 elm_map_route_node_get(const Elm_Map_Route *route)
4785 {
4786 #ifdef HAVE_ELEMENTARY_ECORE_CON
4787    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
4788    return route->info.nodes;
4789 #else
4790    (void) route;
4791    return NULL;
4792 #endif
4793 }
4794
4795 EAPI const char*
4796 elm_map_route_waypoint_get(const Elm_Map_Route *route)
4797 {
4798 #ifdef HAVE_ELEMENTARY_ECORE_CON
4799    EINA_SAFETY_ON_NULL_RETURN_VAL(route, NULL);
4800    return route->info.waypoints;
4801 #else
4802    (void) route;
4803    return NULL;
4804 #endif
4805 }
4806
4807 EAPI const char *
4808 elm_map_name_address_get(const Elm_Map_Name *name)
4809 {
4810 #ifdef HAVE_ELEMENTARY_ECORE_CON
4811    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
4812    return name->address;
4813 #else
4814    (void) name;
4815    return NULL;
4816 #endif
4817 }
4818
4819 EAPI void
4820 elm_map_name_region_get(const Elm_Map_Name *name, double *lon, double *lat)
4821 {
4822 #ifdef HAVE_ELEMENTARY_ECORE_CON
4823    EINA_SAFETY_ON_NULL_RETURN(name);
4824    if (lon) *lon = name->lon;
4825    if (lat) *lat = name->lat;
4826 #else
4827    (void) name;
4828    (void) lon;
4829    (void) lat;
4830 #endif
4831 }
4832
4833 EAPI void
4834 elm_map_name_remove(Elm_Map_Name *name)
4835 {
4836 #ifdef HAVE_ELEMENTARY_ECORE_CON
4837    EINA_SAFETY_ON_NULL_RETURN(name);
4838    if (name->address)
4839      {
4840         free(name->address);
4841         name->address = NULL;
4842      }
4843    if (name->handler)
4844      {
4845         ecore_event_handler_del(name->handler);
4846         name->handler = NULL;
4847      }
4848    if (name->ud.fname)
4849      {
4850         ecore_file_remove(name->ud.fname);
4851         free(name->ud.fname);
4852         name->ud.fname = NULL;
4853      }
4854 #else
4855    (void) name;
4856 #endif
4857 }
4858
4859 EAPI void
4860 elm_map_rotate_set(Evas_Object *obj, double degree, Evas_Coord cx, Evas_Coord cy)
4861 {
4862 #ifdef HAVE_ELEMENTARY_ECORE_CON
4863    ELM_CHECK_WIDTYPE(obj, widtype);
4864    Widget_Data *wd = elm_widget_data_get(obj);
4865
4866    if (!wd) return;
4867    wd->rotate.d = degree;
4868    wd->rotate.cx = cx;
4869    wd->rotate.cy = cy;
4870    wd->calc_job = ecore_job_add(_calc_job, wd);
4871 #else
4872    (void) obj;
4873    (void) degree;
4874    (void) cx;
4875    (void) cy;
4876 #endif
4877 }
4878
4879 EAPI void
4880 elm_map_rotate_get(const Evas_Object *obj, double *degree, Evas_Coord *cx, Evas_Coord *cy)
4881 {
4882 #ifdef HAVE_ELEMENTARY_ECORE_CON
4883    ELM_CHECK_WIDTYPE(obj, widtype);
4884    Widget_Data *wd = elm_widget_data_get(obj);
4885
4886    if (!wd) return;
4887    if (degree) *degree = wd->rotate.d;
4888    if (cx) *cx = wd->rotate.cx;
4889    if (cy) *cy = wd->rotate.cy;
4890 #else
4891    (void) obj;
4892    (void) degree;
4893    (void) cx;
4894    (void) cy;
4895 #endif
4896 }
4897
4898 EAPI void
4899 elm_map_wheel_disabled_set(Evas_Object *obj, Eina_Bool disabled)
4900 {
4901 #ifdef HAVE_ELEMENTARY_ECORE_CON
4902    ELM_CHECK_WIDTYPE(obj, widtype);
4903    Widget_Data *wd = elm_widget_data_get(obj);
4904
4905    if (!wd) return;
4906    if ((!wd->wheel_disabled) && (disabled))
4907      evas_object_event_callback_del_full(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
4908    else if ((wd->wheel_disabled) && (!disabled))
4909      evas_object_event_callback_add(wd->rect, EVAS_CALLBACK_MOUSE_WHEEL, _mouse_wheel_cb, obj);
4910    wd->wheel_disabled = !!disabled;
4911 #else
4912    (void) obj;
4913    (void) disabled;
4914 #endif
4915 }
4916
4917 EAPI Eina_Bool
4918 elm_map_wheel_disabled_get(const Evas_Object *obj)
4919 {
4920 #ifdef HAVE_ELEMENTARY_ECORE_CON
4921    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4922    Widget_Data *wd = elm_widget_data_get(obj);
4923
4924    if (!wd) return EINA_FALSE;
4925    return wd->wheel_disabled;
4926 #else
4927    (void) obj;
4928    return EINA_FALSE;
4929 #endif
4930 }
4931
4932 #ifdef ELM_EMAP
4933 EAPI Evas_Object *
4934 elm_map_track_add(Evas_Object *obj, EMap_Route *emap)
4935 {
4936 #ifdef HAVE_ELEMENTARY_ECORE_CON
4937    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4938    Widget_Data *wd = elm_widget_data_get(obj);
4939
4940    if (!wd) return EINA_FALSE;
4941
4942    Evas_Object *route = elm_route_add(obj);
4943    elm_route_emap_set(route, emap);
4944    wd->track = eina_list_append(wd->track, route);
4945
4946    return route;
4947 #else
4948    (void) obj;
4949    (void) emap;
4950    return NULL;
4951 #endif
4952 }
4953 #endif
4954
4955 EAPI void
4956 elm_map_track_remove(Evas_Object *obj, Evas_Object *route)
4957 {
4958 #ifdef HAVE_ELEMENTARY_ECORE_CON
4959    ELM_CHECK_WIDTYPE(obj, widtype) ;
4960    Widget_Data *wd = elm_widget_data_get(obj);
4961
4962    if (!wd) return ;
4963
4964    wd->track = eina_list_remove(wd->track, route);
4965    evas_object_del(route);
4966 #else
4967    (void) obj;
4968    (void) route;
4969 #endif
4970 }
4971
4972 #ifdef HAVE_ELEMENTARY_ECORE_CON
4973
4974 static char *
4975 _mapnik_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
4976 {
4977    char buf[PATH_MAX];
4978    snprintf(buf, sizeof(buf), "http://tile.openstreetmap.org/%d/%d/%d.png",
4979           zoom, x, y);
4980    return strdup(buf);
4981 }
4982
4983 static char *
4984 _osmarender_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
4985 {
4986    char buf[PATH_MAX];
4987    snprintf(buf, sizeof(buf),
4988             "http://tah.openstreetmap.org/Tiles/tile/%d/%d/%d.png",
4989             zoom, x, y);
4990    return strdup(buf);
4991 }
4992
4993 static char *
4994 _cyclemap_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
4995 {
4996    char buf[PATH_MAX];
4997    snprintf(buf, sizeof(buf),
4998             "http://andy.sandbox.cloudmade.com/tiles/cycle/%d/%d/%d.png",
4999             zoom, x, y);
5000    return strdup(buf);
5001 }
5002
5003 static char *
5004 _maplint_url_cb(Evas_Object *obj __UNUSED__, int x, int y, int zoom)
5005 {
5006    char buf[PATH_MAX];
5007    snprintf(buf, sizeof(buf),
5008             "http://tah.openstreetmap.org/Tiles/maplint/%d/%d/%d.png",
5009             zoom, x, y);
5010    return strdup(buf);
5011 }
5012
5013 static char *_yours_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5014 {
5015    char buf[PATH_MAX];
5016    snprintf(buf, sizeof(buf),
5017             "%s?flat=%lf&flon=%lf&tlat=%lf&tlon=%lf&v=%s&fast=%d&instructions=1",
5018             ROUTE_YOURS_URL, flat, flon, tlat, tlon, type_name, method);
5019
5020    return strdup(buf);
5021 }
5022
5023 // TODO: fix monav api
5024 /*
5025 static char *_monav_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5026 {
5027    char buf[PATH_MAX];
5028    snprintf(buf, sizeof(buf),
5029             "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
5030             ROUTE_MONAV_URL, flat, flon, tlat, tlon, type_name, method);
5031
5032    return strdup(buf);
5033 }
5034 */
5035
5036 // TODO: fix ors api
5037 /*
5038 static char *_ors_url_cb(Evas_Object *obj __UNUSED__, char *type_name, int method, double flon, double flat, double tlon, double tlat)
5039 {
5040    char buf[PATH_MAX];
5041    snprintf(buf, sizeof(buf),
5042             "%s?flat=%f&flon=%f&tlat=%f&tlon=%f&v=%s&fast=%d&instructions=1",
5043             ROUTE_ORS_URL, flat, flon, tlat, tlon, type_name, method);
5044
5045    return strdup(buf);
5046 }
5047 */
5048
5049 static char *
5050 _nominatim_url_cb(Evas_Object *obj, int method, char *name, double lon, double lat)
5051 {
5052    ELM_CHECK_WIDTYPE(obj, widtype) strdup("");
5053    Widget_Data *wd = elm_widget_data_get(obj);
5054    char **str;
5055    unsigned int ele, idx;
5056    char search_url[PATH_MAX];
5057    char buf[PATH_MAX];
5058
5059    if (!wd) return strdup("");
5060    if (method == ELM_MAP_NAME_METHOD_SEARCH)
5061      {
5062         search_url[0] = '\0';
5063         str = eina_str_split_full(name, " ", 0, &ele);
5064         for (idx = 0 ; idx < ele ; idx++)
5065           {
5066              eina_strlcat(search_url, str[idx], sizeof(search_url));
5067              if (!(idx == (ele-1))) eina_strlcat(search_url, "+", sizeof(search_url));
5068           }
5069         snprintf(buf, sizeof(buf), "%s/search?q=%s&format=xml&polygon=0&addressdetails=0", NAME_NOMINATIM_URL, search_url);
5070      }
5071    else if (method == ELM_MAP_NAME_METHOD_REVERSE) snprintf(buf, sizeof(buf), "%s/reverse?format=xml&lat=%lf&lon=%lf&zoom=%d&addressdetails=0", NAME_NOMINATIM_URL, lat, lon, wd->zoom);
5072    else strcpy(buf, "");
5073
5074    return strdup(buf);
5075 }
5076
5077 #endif