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