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