elementary/map - map supports language,changed
[framework/uifw/elementary.git] / src / lib / elm_widget_map.h
1 #ifndef ELM_WIDGET_MAP_H
2 #define ELM_WIDGET_MAP_H
3
4 #include "elm_interface_scrollable.h"
5
6 /**
7  * @addtogroup Widget
8  * @{
9  *
10  * @section elm-map-class The Elementary Map Class
11  *
12  * Elementary, besides having the @ref Map widget, exposes its
13  * foundation -- the Elementary Map Class -- in order to create
14  * other widgets which are a map with some more logic on top.
15  */
16
17 /**
18  * @def ELM_MAP_CLASS
19  *
20  * Use this macro to cast whichever subclass of
21  * #Elm_Map_Smart_Class into it, so to access its fields.
22  *
23  * @ingroup Widget
24  */
25 #define ELM_MAP_CLASS(x) ((Elm_Map_Smart_Class *) x)
26
27 /**
28  * @def ELM_MAP_DATA
29  *
30  * Use this macro to cast whichever subdata of
31  * #Elm_Map_Smart_Data into it, so to access its fields.
32  *
33  * @ingroup Widget
34  */
35 #define ELM_MAP_DATA(x) ((Elm_Map_Smart_Data *) x)
36
37 /**
38  * @def ELM_MAP_SMART_CLASS_VERSION
39  *
40  * Current version for Elementary map @b base smart class, a value
41  * which goes to _Elm_Map_Smart_Class::version.
42  *
43  * @ingroup Widget
44  */
45 #define ELM_MAP_SMART_CLASS_VERSION 1
46
47 /**
48  * @def ELM_MAP_SMART_CLASS_INIT
49  *
50  * Initializer for a whole #Elm_Map_Smart_Class structure, with
51  * @c NULL values on its specific fields.
52  *
53  * @param smart_class_init initializer to use for the "base" field
54  * (#Evas_Smart_Class).
55  *
56  * @see EVAS_SMART_CLASS_INIT_NULL
57  * @see EVAS_SMART_CLASS_INIT_NAME_VERSION
58  * @see ELM_MAP_SMART_CLASS_INIT_NULL
59  * @see ELM_MAP_SMART_CLASS_INIT_NAME_VERSION
60  *
61  * @ingroup Widget
62  */
63 #define ELM_MAP_SMART_CLASS_INIT(smart_class_init)                        \
64   {smart_class_init, ELM_MAP_SMART_CLASS_VERSION}
65
66 /**
67  * @def ELM_MAP_SMART_CLASS_INIT_NULL
68  *
69  * Initializer to zero out a whole #Elm_Map_Smart_Class structure.
70  *
71  * @see ELM_MAP_SMART_CLASS_INIT_NAME_VERSION
72  * @see ELM_MAP_SMART_CLASS_INIT
73  *
74  * @ingroup Widget
75  */
76 #define ELM_MAP_SMART_CLASS_INIT_NULL \
77   ELM_MAP_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
78
79 /**
80  * @def ELM_MAP_SMART_CLASS_INIT_NAME_VERSION
81  *
82  * Initializer to zero out a whole #Elm_Map_Smart_Class structure and
83  * set its name and version.
84  *
85  * This is similar to #ELM_MAP_SMART_CLASS_INIT_NULL, but it will
86  * also set the version field of #Elm_Map_Smart_Class (base field)
87  * to the latest #ELM_MAP_SMART_CLASS_VERSION and name it to the
88  * specific value.
89  *
90  * It will keep a reference to the name field as a <c>"const char *"</c>,
91  * i.e., the name must be available while the structure is
92  * used (hint: static or global variable!) and must not be modified.
93  *
94  * @see ELM_MAP_SMART_CLASS_INIT_NULL
95  * @see ELM_MAP_SMART_CLASS_INIT
96  *
97  * @ingroup Widget
98  */
99 #define ELM_MAP_SMART_CLASS_INIT_NAME_VERSION(name) \
100   ELM_MAP_SMART_CLASS_INIT(ELM_WIDGET_SMART_CLASS_INIT_NAME_VERSION(name))
101
102 /**
103  * Elementary map base smart class. This inherits directly from
104  * #Elm_Widget_Smart_Class and is meant to build widgets extending the
105  * behavior of a map.
106  *
107  * All of the functions listed on @ref Map namespace will work for
108  * objects deriving from #Elm_Map_Smart_Class.
109  */
110 typedef struct _Elm_Map_Smart_Class
111 {
112    Elm_Widget_Smart_Class base;
113
114    int                    version; /**< Version of this smart class definition */
115 } Elm_Map_Smart_Class;
116
117 /**
118  * Base widget smart data extended with map instance data.
119  */
120 typedef struct _Elm_Map_Smart_Data     Elm_Map_Smart_Data;
121
122 typedef struct _Elm_Map_Name_List      Elm_Map_Name_List;
123 typedef char *(*Elm_Map_Module_Source_Name_Func)(void);
124 typedef int   (*Elm_Map_Module_Tile_Zoom_Min_Func)(void);
125 typedef int   (*Elm_Map_Module_Tile_Zoom_Max_Func)(void);
126 typedef char *(*Elm_Map_Module_Tile_Url_Func)(const Evas_Object *,
127                                               int,
128                                               int,
129                                               int);
130 typedef Eina_Bool (*Elm_Map_Module_Tile_Geo_to_Coord_Func)(const Evas_Object *,
131                                                            int,
132                                                            double,
133                                                            double,
134                                                            int,
135                                                            int *,
136                                                            int *);
137 typedef Eina_Bool (*Elm_Map_Module_Tile_Coord_to_Geo_Func)(const Evas_Object *,
138                                                            int,
139                                                            int,
140                                                            int,
141                                                            int,
142                                                            double *,
143                                                            double *);
144 typedef double (*Elm_Map_Module_Tile_Scale_Func)(const Evas_Object *,
145                                                  double,
146                                                  double,
147                                                  int);
148 typedef char *(*Elm_Map_Module_Route_Url_Func)(const Evas_Object *,
149                                                const char *,
150                                                int,
151                                                double,
152                                                double,
153                                                double,
154                                                double);
155 typedef char *(*Elm_Map_Module_Name_Url_Func)(const Evas_Object *,
156                                               int,
157                                               const char *,
158                                               double,
159                                               double);
160
161 typedef Evas_Object *(*Elm_Map_Module_Add_Func)(Evas_Object *parent);
162 typedef void (*Elm_Map_Module_Del_Func)(Evas_Object *parent);
163 typedef void (*Elm_Map_Module_Move_Func)(Evas_Object *parent,
164                                          int x,
165                                          int y);
166 typedef void (*Elm_Map_Module_Resize_Func)(Evas_Object *parent,
167                                            int w,
168                                            int h);
169 typedef void (*Elm_Map_Module_Pan_Func)(Evas_Object *,
170                                         int x1,
171                                         int y1,
172                                         int x2,
173                                         int y2);
174 typedef void (*Elm_Map_Module_Show_Func)(Evas_Object *,
175                                          double lon,
176                                          double lat,
177                                          int animation);
178 typedef void (*Elm_Map_Module_Zoom_Func)(Evas_Object *,
179                                          double zoom,
180                                          int animation);
181 typedef void (*Elm_Map_Module_Rotate_Func)(Evas_Object *,
182                                            double angle,
183                                            int x,
184                                            int y,
185                                            int animation);
186 typedef void (*Elm_Map_Module_Rotate_Get_Func)(const Evas_Object *,
187                                                double *angle,
188                                                int *x,
189                                                int *y);
190 typedef void (*Elm_Map_Module_Perspective_Set_Func)(Evas_Object *,
191                                                     double perpective,
192                                                     int animation);
193 typedef void (*Elm_Map_Module_Region_Get_Func)(const Evas_Object *,
194                                                double *lon,
195                                                double *lat);
196 typedef void (*Elm_Map_Module_Canvas_to_Region_Func)(const Evas_Object *,
197                                                      int x,
198                                                      int y,
199                                                      double *lon,
200                                                      double *lat);
201 typedef void (*Elm_Map_Module_Region_to_Canvas_Func)(const Evas_Object *,
202                                                      double lon,
203                                                      double lat,
204                                                      int *x,
205                                                      int *y);
206
207 typedef struct _Source_Tile            Source_Tile;
208 // FIXME: Currently tile size must be 256*256
209 // and the map size is pow(2.0, z) * (tile size)
210 struct _Source_Tile
211 {
212    const char                           *name;
213    int                                   zoom_min;
214    int                                   zoom_max;
215    Elm_Map_Module_Tile_Url_Func          url_cb;
216    Elm_Map_Module_Tile_Geo_to_Coord_Func geo_to_coord;
217    Elm_Map_Module_Tile_Coord_to_Geo_Func coord_to_geo;
218    Elm_Map_Module_Tile_Scale_Func        scale_cb;
219 };
220
221 typedef struct _Source_Route           Source_Route;
222 struct _Source_Route
223 {
224    const char                   *name;
225    Elm_Map_Module_Route_Url_Func url_cb;
226 };
227
228 typedef struct _Source_Name            Source_Name;
229 struct _Source_Name
230 {
231    const char                  *name;
232    Elm_Map_Module_Name_Url_Func url_cb;
233 };
234
235 typedef struct _Source_Engine            Source_Engine;
236 struct _Source_Engine
237 {
238    const char                           *name;
239    int                                   zoom_min;
240    int                                   zoom_max;
241
242    Elm_Map_Module_Add_Func               add;
243    Elm_Map_Module_Del_Func               del;
244    Elm_Map_Module_Move_Func              move;
245    Elm_Map_Module_Resize_Func            resize;
246    Elm_Map_Module_Pan_Func               pan;
247    Elm_Map_Module_Show_Func              show;
248    Elm_Map_Module_Zoom_Func              zoom;
249    Elm_Map_Module_Rotate_Func            rotate;
250    Elm_Map_Module_Rotate_Get_Func        rotate_get;
251    Elm_Map_Module_Perspective_Set_Func   perpective;
252    Elm_Map_Module_Region_Get_Func        region_get;
253    Elm_Map_Module_Canvas_to_Region_Func  canvas_to_region;
254    Elm_Map_Module_Region_to_Canvas_Func  region_to_canvas;
255 };
256
257 typedef struct _Path                   Path;
258 typedef struct _Color                  Color;
259 typedef struct _Region                 Region;
260 typedef struct _Grid                   Grid;
261 typedef struct _Grid_Item              Grid_Item;
262 typedef struct _Overlay_Default        Overlay_Default;
263 typedef struct _Overlay_Class          Overlay_Class;
264 typedef struct _Overlay_Group          Overlay_Group;
265 typedef struct _Overlay_Bubble         Overlay_Bubble;
266 typedef struct _Overlay_Route          Overlay_Route;
267 typedef struct _Overlay_Line           Overlay_Line;
268 typedef struct _Overlay_Polygon        Overlay_Polygon;
269 typedef struct _Overlay_Circle         Overlay_Circle;
270 typedef struct _Overlay_Scale          Overlay_Scale;
271 typedef struct _Path_Node              Path_Node;
272 typedef struct _Path_Waypoint          Path_Waypoint;
273 typedef struct _Route_Dump             Route_Dump;
274 typedef struct _Name_Dump              Name_Dump;
275 typedef struct _Calc_Job               Calc_Job;
276
277 enum _Route_Xml_Attribute
278 {
279    ROUTE_XML_NONE,
280    ROUTE_XML_DISTANCE,
281    ROUTE_XML_DESCRIPTION,
282    ROUTE_XML_COORDINATES,
283    ROUTE_XML_LAST
284 } Route_Xml_Attibute;
285
286 enum _Name_Xml_Attribute
287 {
288    NAME_XML_NONE,
289    NAME_XML_NAME,
290    NAME_XML_LON,
291    NAME_XML_LAT,
292    NAME_XML_LAST
293 } Name_Xml_Attibute;
294
295 enum _Track_Xml_Attribute
296 {
297    TRACK_XML_NONE,
298    TRACK_XML_COORDINATES,
299    TRACK_XML_LAST
300 } Track_Xml_Attibute;
301
302 struct _Path
303 {
304    Evas_Coord x, y;
305 };
306
307 struct _Region
308 {
309    double lon, lat;
310 };
311
312 struct _Color
313 {
314    int r, g, b, a;
315 };
316
317 struct _Overlay_Group
318 {
319    Elm_Map_Smart_Data *wsd;
320    double              lon, lat;
321    Elm_Map_Overlay    *overlay; // virtual group type overlay
322    Elm_Map_Overlay    *klass; // class overlay for this virtual group
323    Overlay_Default    *ovl;  // rendered overlay
324    Eina_List          *members;
325    Eina_Bool           in : 1;
326    Eina_Bool           boss : 1;
327 };
328
329 struct _Overlay_Default
330 {
331    Elm_Map_Smart_Data *wsd;
332    Evas_Coord          w, h;
333
334    double              lon, lat;
335    Evas_Coord          x, y;
336
337    // Display priority is content > icon > clas_obj > clas_icon > layout
338    Evas_Object        *content;
339    Evas_Object        *icon;
340
341    Color               c;
342    // if clas_content or icon exists, do not inherit from class
343    Evas_Object        *clas_content; // Duplicated from class content
344    Evas_Object        *clas_icon; // Duplicated from class icon
345    Evas_Object        *layout;
346 };
347
348 struct _Overlay_Class
349 {
350    Elm_Map_Smart_Data *wsd;
351    Eina_List          *members;
352    int                 zoom_max;
353    Evas_Object        *content;
354    Evas_Object        *icon;
355 };
356
357 struct _Overlay_Bubble
358 {
359    Elm_Map_Smart_Data *wsd;
360    Evas_Object        *pobj;
361    Evas_Object        *obj, *sc, *bx;
362    double              lon, lat;
363    Evas_Coord          x, y, w, h;
364 };
365
366 struct _Overlay_Route
367 {
368    Elm_Map_Smart_Data *wsd;
369
370    Evas_Object        *obj;
371    Eina_List          *paths;
372    Eina_List          *nodes;
373 };
374
375 struct _Overlay_Line
376 {
377    Elm_Map_Smart_Data *wsd;
378    double              flon, flat, tlon, tlat;
379    Evas_Object        *obj;
380 };
381
382 struct _Overlay_Polygon
383 {
384    Elm_Map_Smart_Data *wsd;
385    Eina_List          *regions; // list of Regions
386    Evas_Object        *obj;
387 };
388
389 struct _Overlay_Circle
390 {
391    Elm_Map_Smart_Data *wsd;
392    double              lon, lat;
393    double              radius; // Intial pixel in intial view
394    double              ratio; // initial-radius/map-size
395    Evas_Object        *obj;
396 };
397
398 struct _Overlay_Scale
399 {
400    Elm_Map_Smart_Data *wsd;
401    Evas_Coord          x, y;
402    Evas_Coord          w, h;
403    Evas_Object        *obj;
404 };
405
406 struct _Elm_Map_Overlay
407 {
408    Elm_Map_Smart_Data    *wsd;
409
410    Evas_Coord             zoom_min;
411    Color                  c;
412    void                  *data; // user set data
413
414    Elm_Map_Overlay_Type   type;
415    void                  *ovl; // Overlay Data for each type
416
417    Elm_Map_Overlay_Get_Cb cb;
418    void                  *cb_data;
419
420    Elm_Map_Overlay_Del_Cb del_cb;
421    void                  *del_cb_data;
422
423    // These are not used if overlay type is class or group
424    Overlay_Group         *grp;
425
426    Eina_Bool              visible : 1;
427    Eina_Bool              paused : 1;
428    Eina_Bool              hide : 1;
429 };
430
431 struct _Elm_Map_Route
432 {
433    Elm_Map_Smart_Data      *wsd;
434
435    char                    *fname;
436    Elm_Map_Route_Type       type;
437    Elm_Map_Route_Method     method;
438    double                   flon, flat, tlon, tlat;
439    Elm_Map_Route_Cb         cb;
440    void                    *data;
441    Ecore_File_Download_Job *job;
442
443    Eina_List               *nodes;
444    Eina_List               *waypoint;
445    struct
446    {
447       int         node_count;
448       int         waypoint_count;
449       const char *nodes;
450       const char *waypoints;
451       double      distance; /* unit : km */
452    } info;
453
454    Path_Node               *n;
455    Path_Waypoint           *w;
456 };
457
458 struct _Path_Node
459 {
460    Elm_Map_Smart_Data *wsd;
461
462    int                 idx;
463    struct
464    {
465       double lon, lat;
466       char  *address;
467    } pos;
468 };
469
470 struct _Path_Waypoint
471 {
472    Elm_Map_Smart_Data *wsd;
473
474    const char         *point;
475 };
476
477 struct _Elm_Map_Name
478 {
479    Elm_Map_Smart_Data      *wsd;
480
481    int                      method;
482    char                    *address;
483    double                   lon, lat;
484
485    char                    *fname;
486    Ecore_File_Download_Job *job;
487    Elm_Map_Name_Cb          cb;
488    void                    *data;
489 };
490
491 struct _Elm_Map_Name_List
492 {
493    Elm_Map_Smart_Data      *wsd;
494
495    Eina_List               *names;
496    double                   lon, lat;
497
498    char                    *fname;
499    Ecore_File_Download_Job *job;
500    Elm_Map_Name_List_Cb     cb;
501    void                    *data;
502 };
503
504 struct _Route_Dump
505 {
506    int    id;
507    char  *fname;
508    double distance;
509    char  *description;
510    char  *coordinates;
511 };
512
513 struct _Name_Dump
514 {
515    int    id;
516    char  *address;
517    double lon;
518    double lat;
519 };
520
521 struct _Grid_Item
522 {
523    Grid                    *g;
524
525    Elm_Map_Smart_Data      *wsd;
526    Evas_Object             *img;
527    const char              *file;
528    const char              *url;
529    int                      x, y; // Tile coordinate
530
531    Ecore_File_Download_Job *job;
532
533    Eina_Bool                file_have : 1;
534 };
535
536 struct _Grid
537 {
538    Elm_Map_Smart_Data *wsd;
539    int                 zoom;  /* zoom level tiles want for optimal
540                                * display (1, 2, 4, 8) */
541    int                 tw, th; // size of grid in tiles
542    Eina_Matrixsparse  *grid;
543 };
544
545 struct _Calc_Job
546 {
547    Eina_Bool show_changed : 1;
548    Eina_Bool show_anim : 1;
549    double lon, lat;
550
551    Eina_Bool zoom_changed : 1;
552    Eina_Bool zoom_anim : 1;
553    double zoom;
554
555    Eina_Bool overlays_changed : 1;
556    Eina_List *overlays;
557 };
558
559 struct _Elm_Map_Smart_Data
560 {
561    Elm_Widget_Smart_Data                 base; /* base widget smart data as
562                                                 * first member obligatory, as
563                                                 * we're inheriting from it */
564
565    Evas_Object                          *layout;
566    Evas_Object                          *hit_rect;
567    const Elm_Scrollable_Smart_Interface *s_iface;
568    Evas_Object                          *pan_obj;
569    Evas_Object                          *g_layer;
570
571    /* Tiles are below this and overlays are on top */
572    Evas_Object                          *sep_maps_overlays;
573    Evas_Map                             *map;
574
575    Eina_Array                           *src_mods;
576
577    Source_Engine                        *engine;
578    Eina_List                            *engines;
579    const char                          **engine_names;
580
581    Source_Tile                          *src_tile;
582    Eina_List                            *src_tiles;
583    const char                          **src_tile_names;
584
585    Source_Route                         *src_route;
586    Eina_List                            *src_routes;
587    const char                          **src_route_names;
588
589    Source_Name                          *src_name;
590    Eina_List                            *src_names;
591    const char                          **src_name_names;
592
593    Eina_List                            *grids;
594
595    int                                   zoom_min, zoom_max;
596    int                                   tsize;
597    int                                   id;
598    int                                   zoom;
599
600    double                                zoom_detail;
601    struct
602    {
603       int w, h;    // Current pixel width, heigth of a grid
604       int tile;    // Current pixel size of a grid item
605    } size;
606
607    Elm_Map_Zoom_Mode                     mode;
608
609    struct
610    {
611       double zoom;
612       double diff;
613       int    cnt;
614    } ani;
615
616    Ecore_Timer                          *zoom_timer;
617    Ecore_Animator                       *zoom_animator;
618    Ecore_Timer                          *loaded_timer;
619
620    int                                   try_num;
621    int                                   finish_num;
622    int                                   download_num;
623
624    Eina_List                            *download_list;
625    Ecore_Idler                          *download_idler;
626    Eina_Hash                            *ua;
627    const char                           *user_agent;
628
629    Evas_Coord                            pan_x, pan_y;
630
631    Ecore_Timer                          *scr_timer;
632    Ecore_Timer                          *long_timer;
633    Evas_Event_Mouse_Down                 ev;
634
635    double                                pinch_zoom;
636    struct
637    {
638       Evas_Coord cx, cy;
639       double     d;
640    } pan_rotate;
641
642    struct
643      {
644         double a, d;
645      } pinch_rotate;
646
647    struct
648      {
649         unsigned int st;
650         int x, y;
651         double perspect;
652         double perspect_y;
653      } pinch_pan;
654
655    Eina_List                            *routes;
656    Eina_List                            *track;
657    Eina_List                            *names;
658
659    Eina_List                            *overlays;
660    Eina_List                            *group_overlays;
661    Eina_List                            *all_overlays;
662
663    Eina_Bool                             wheel_disabled : 1;
664    Eina_Bool                             on_hold : 1;
665    Eina_Bool                             paused : 1;
666
667    Calc_Job                               calc_job;
668 };
669
670 typedef struct _Elm_Map_Pan_Smart_Class
671 {
672    Elm_Pan_Smart_Class base;
673 } Elm_Map_Pan_Smart_Class;
674
675 typedef struct _Elm_Map_Pan_Smart_Data Elm_Map_Pan_Smart_Data;
676 struct _Elm_Map_Pan_Smart_Data
677 {
678    Elm_Pan_Smart_Data  base;
679    Elm_Map_Smart_Data *wsd;
680 };
681
682 /**
683  * @}
684  */
685
686 EAPI extern const char ELM_MAP_SMART_NAME[];
687 EAPI extern const char ELM_MAP_PAN_SMART_NAME[];
688 EAPI const Elm_Map_Smart_Class *elm_map_smart_class_get(void);
689
690 #define ELM_MAP_DATA_GET(o, sd) \
691   Elm_Map_Smart_Data * sd = evas_object_smart_data_get(o)
692
693 #define ELM_MAP_PAN_DATA_GET(o, sd) \
694   Elm_Map_Pan_Smart_Data * sd = evas_object_smart_data_get(o)
695
696 #define ELM_MAP_DATA_GET_OR_RETURN(o, ptr)      \
697   ELM_MAP_DATA_GET(o, ptr);                     \
698   if (!ptr)                                          \
699     {                                                \
700        CRITICAL("No widget data for object %p (%s)", \
701                 o, evas_object_type_get(o));         \
702        return;                                       \
703     }
704
705 #define ELM_MAP_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
706   ELM_MAP_DATA_GET(o, ptr);                         \
707   if (!ptr)                                              \
708     {                                                    \
709        CRITICAL("No widget data for object %p (%s)",     \
710                 o, evas_object_type_get(o));             \
711        return val;                                       \
712     }
713
714 #define ELM_MAP_CHECK(obj)                     \
715   if (!obj || !elm_widget_type_check                \
716         ((obj), ELM_MAP_SMART_NAME, __func__)) \
717     return
718
719 #endif