Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Interop / Interop.View.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19 using ElmSharp;
20
21 internal static partial class Interop
22 {
23     internal enum ViewType
24     {
25         Normal, // MAPS_VIEW_TYPE_NORMAL
26         Satellite, // MAPS_VIEW_TYPE_SATELLITE
27         Terrain, // MAPS_VIEW_TYPE_TERRAIN
28         Hybrid, // MAPS_VIEW_TYPE_HYBRID
29     }
30
31     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
32     internal delegate void ViewOnEventCallback(ViewEventType /* maps_view_event_type_e */ type, IntPtr /* maps_view_event_data_h */ eventData, IntPtr /* void */ userData);
33
34
35     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_zoom_level")]
36     internal static extern ErrorCode GetZoomLevel(this ViewHandle /* maps_view_h */ view, out int level);
37
38     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_zoom_level")]
39     internal static extern ErrorCode SetZoomLevel(this ViewHandle /* maps_view_h */ view, int level);
40
41     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_min_zoom_level")]
42     internal static extern ErrorCode GetMinZoomLevel(this ViewHandle /* maps_view_h */ view, out int minZoomLevel);
43
44     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_min_zoom_level")]
45     internal static extern ErrorCode SetMinZoomLevel(this ViewHandle /* maps_view_h */ view, int minZoomLevel);
46
47     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_max_zoom_level")]
48     internal static extern ErrorCode GetMaxZoomLevel(this ViewHandle /* maps_view_h */ view, out int maxZoomLevel);
49
50     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_max_zoom_level")]
51     internal static extern ErrorCode SetMaxZoomLevel(this ViewHandle /* maps_view_h */ view, int maxZoomLevel);
52
53     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_orientation")]
54     internal static extern ErrorCode GetOrientation(this ViewHandle /* maps_view_h */ view, out double rotationAngle);
55
56     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_orientation")]
57     internal static extern ErrorCode SetOrientation(this ViewHandle /* maps_view_h */ view, double rotationAngle);
58
59     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_language")]
60     internal static extern ErrorCode GetLanguage(this ViewHandle /* maps_view_h */ view, out string language);
61
62     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_language")]
63     internal static extern ErrorCode SetLanguage(this ViewHandle /* maps_view_h */ view, string language);
64
65     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_type")]
66     internal static extern ErrorCode SetMapType(this ViewHandle /* maps_view_h */ view, ViewType /* maps_view_type_e */ type);
67
68     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_type")]
69     internal static extern ErrorCode GetMapType(this ViewHandle /* maps_view_h */ view, out ViewType /* maps_view_type_e */ type);
70
71     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_buildings_enabled")]
72     internal static extern ErrorCode GetBuildingsEnabled(this ViewHandle /* maps_view_h */ view, out bool enable);
73
74     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_buildings_enabled")]
75     internal static extern ErrorCode SetBuildingsEnabled(this ViewHandle /* maps_view_h */ view, bool enable);
76
77     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_traffic_enabled")]
78     internal static extern ErrorCode GetTrafficEnabled(this ViewHandle /* maps_view_h */ view, out bool enable);
79
80     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_traffic_enabled")]
81     internal static extern ErrorCode SetTrafficEnabled(this ViewHandle /* maps_view_h */ view, bool enable);
82
83     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_public_transit_enabled")]
84     internal static extern ErrorCode GetPublicTransitEnabled(this ViewHandle /* maps_view_h */ view, out bool enable);
85
86     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_public_transit_enabled")]
87     internal static extern ErrorCode SetPublicTransitEnabled(this ViewHandle /* maps_view_h */ view, bool enable);
88
89     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_scalebar_enabled")]
90     internal static extern ErrorCode GetScaleBarEnabled(this ViewHandle /* maps_view_h */ view, out bool enabled);
91
92     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_scalebar_enabled")]
93     internal static extern ErrorCode SetScaleBarEnabled(this ViewHandle /* maps_view_h */ view, bool enable);
94
95     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_screen_location")]
96     internal static extern ErrorCode GetScreenLocation(this ViewHandle /* maps_view_h */ view, out int x, out int y, out int width, out int height);
97
98     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_screen_location")]
99     internal static extern ErrorCode SetScreenLocation(this ViewHandle /* maps_view_h */ view, int x, int y, int width, int height);
100
101     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_visibility")]
102     internal static extern ErrorCode GetVisibility(this ViewHandle /* maps_view_h */ view, out bool visible);
103
104     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_visibility")]
105     internal static extern ErrorCode SetVisibility(this ViewHandle /* maps_view_h */ view, bool visible);
106
107     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_viewport")]
108     internal static extern ErrorCode GetViewport(this ViewHandle /* maps_view_h */ view, out IntPtr viewport);
109
110     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_center")]
111     internal static extern ErrorCode GetCenter(this ViewHandle /* maps_view_h */ view, out IntPtr /* maps_coordinates_h */ coordinates);
112
113     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_center")]
114     internal static extern ErrorCode SetCenter(this ViewHandle /* maps_view_h */ view, CoordinatesHandle /* maps_coordinates_h */ coordinates);
115
116
117     [DllImport(Libraries.MapService, EntryPoint = "maps_view_get_gesture_enabled")]
118     internal static extern ErrorCode GetGestureEnabled(this ViewHandle /* maps_view_h */ view, ViewGesture /* maps_view_gesture_e */ gesture, out bool enabled);
119
120     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_gesture_enabled")]
121     internal static extern ErrorCode SetGestureEnabled(this ViewHandle /* maps_view_h */ view, ViewGesture /* maps_view_gesture_e */ gesture, bool enabled);
122
123     [DllImport(Libraries.MapService, EntryPoint = "maps_view_set_event_cb")]
124     internal static extern ErrorCode SetEventCb(this ViewHandle /* maps_view_h */ view, ViewEventType /* maps_view_event_type_e */ type, ViewOnEventCallback callback, IntPtr /* void */ userData);
125
126     [DllImport(Libraries.MapService, EntryPoint = "maps_view_unset_event_cb")]
127     internal static extern ErrorCode UnsetEventCb(this ViewHandle /* maps_view_h */ view, ViewEventType /* maps_view_event_type_e */ type);
128
129     [DllImport(Libraries.MapService, EntryPoint = "maps_view_screen_to_geolocation")]
130     internal static extern ErrorCode ScreenToGeolocation(this ViewHandle /* maps_view_h */ view, int x, int y, out IntPtr /* maps_coordinates_h */ coordinates);
131
132     [DllImport(Libraries.MapService, EntryPoint = "maps_view_geolocation_to_screen")]
133     internal static extern ErrorCode GeolocationToScreen(this ViewHandle /* maps_view_h */ view, CoordinatesHandle /* maps_coordinates_h */ coordinates, out int x, out int y);
134
135     [DllImport(Libraries.MapService, EntryPoint = "maps_view_move")]
136     internal static extern ErrorCode Move(this ViewHandle /* maps_view_h */ view, int x, int y);
137
138     [DllImport(Libraries.MapService, EntryPoint = "maps_view_resize")]
139     internal static extern ErrorCode Resize(this ViewHandle /* maps_view_h */ view, int width, int height);
140
141     [DllImport(Libraries.MapService, EntryPoint = "maps_view_add_object")]
142     internal static extern ErrorCode AddObject(this ViewHandle /* maps_view_h */ view, ViewObjectHandle /* maps_view_object_h */ viewObject);
143
144     [DllImport(Libraries.MapService, EntryPoint = "maps_view_remove_object")]
145     internal static extern ErrorCode RemoveObject(this ViewHandle /* maps_view_h */ view, ViewObjectHandle /* maps_view_object_h */ viewObject);
146
147     [DllImport(Libraries.MapService, EntryPoint = "maps_view_remove_all_objects")]
148     internal static extern ErrorCode RemoveAllObjects(this ViewHandle /* maps_view_h */ view);
149
150     internal class ViewHandle : SafeMapsHandle
151     {
152         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
153         internal delegate bool ViewObjectCallback(int index, int total, IntPtr /* maps_view_object_h */ viewObject, IntPtr /* void */ userData);
154
155         [DllImport(Libraries.MapService, EntryPoint = "maps_view_foreach_object")]
156         internal static extern ErrorCode ForeachObject(ViewHandle /* maps_view_h */ view, ViewObjectCallback callback, IntPtr /* void */ userData);
157
158         [DllImport(Libraries.MapService, EntryPoint = "maps_view_create")]
159         internal static extern ErrorCode Create(ServiceHandle /* maps_service_h */ maps, IntPtr obj, out IntPtr /* maps_view_h */ view);
160
161         [DllImport(Libraries.MapService, EntryPoint = "maps_view_destroy")]
162         internal static extern ErrorCode Destroy(IntPtr /* maps_view_h */ view);
163
164         internal int ZoomLevel
165         {
166             get { return NativeGet<int>(this.GetZoomLevel); }
167             set { NativeSet(this.SetZoomLevel, value); }
168         }
169
170         internal int MinimumZoomLevel
171         {
172             get { return NativeGet<int>(this.GetMinZoomLevel); }
173             set { NativeSet(this.SetMinZoomLevel, value); }
174         }
175
176         internal int MaximumZoomLevel
177         {
178             get { return NativeGet<int>(this.GetMaxZoomLevel); }
179             set { NativeSet(this.SetMaxZoomLevel, value); }
180         }
181
182         internal double Orientation
183         {
184             get { return NativeGet<double>(this.GetOrientation); }
185             set { NativeSet(this.SetOrientation, value); }
186         }
187
188         internal ViewType MapType
189         {
190             get { return NativeGet<ViewType>(this.GetMapType); }
191             set { NativeSet(this.SetMapType, value); }
192         }
193
194         internal bool BuildingsEnabled
195         {
196             get { return NativeGet<bool>(this.GetBuildingsEnabled); }
197             set { NativeSet(this.SetBuildingsEnabled, value); }
198         }
199
200         internal bool TrafficEnabled
201         {
202             get { return NativeGet<bool>(this.GetTrafficEnabled); }
203             set { NativeSet(this.SetTrafficEnabled, value); }
204         }
205
206         internal bool PublicTransitEnabled
207         {
208             get { return NativeGet<bool>(this.GetPublicTransitEnabled); }
209             set { NativeSet(this.SetPublicTransitEnabled, value); }
210         }
211         internal bool ScaleBarEnabled
212         {
213             get { return NativeGet<bool>(this.GetScaleBarEnabled); }
214             set { NativeSet(this.SetScaleBarEnabled, value); }
215         }
216
217         internal string Language
218         {
219             get { return NativeGet(this.GetLanguage); }
220             set { NativeSet(this.SetLanguage, value); }
221         }
222
223         internal bool IsVisible
224         {
225             get { return NativeGet<bool>(this.GetVisibility); }
226             set { NativeSet(this.SetVisibility, value); }
227         }
228
229         internal CoordinatesHandle Center
230         {
231             get { return NativeGet(this.GetCenter, CoordinatesHandle.Create); }
232             set { NativeSet(this.SetCenter, value); }
233         }
234
235         public ViewHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
236         {
237         }
238
239         public ViewHandle(ServiceHandle maps, IntPtr evasObject) : this(IntPtr.Zero, true)
240         {
241             Create(maps, evasObject, out handle).ThrowIfFailed("Failed to create native handle");
242         }
243
244         internal CoordinatesHandle ScreenToGeolocation(Point position)
245         {
246             IntPtr coordinates;
247             this.ScreenToGeolocation(position.X, position.Y, out coordinates).WarnIfFailed("Failed to convert screen position to geocoordinates");
248             return CoordinatesHandle.Create(coordinates);
249         }
250
251         internal Point GeolocationToScreen(CoordinatesHandle coordinates)
252         {
253             int x, y;
254             this.GeolocationToScreen(coordinates, out x, out y).WarnIfFailed("Failed to convert geocoordinates to screen position");
255             return new Point() { X = x, Y = y };
256         }
257     }
258 }