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