[Maps] Modify diposing routines
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Tizen.Maps / Marker.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 ElmSharp;
19
20 namespace Tizen.Maps
21 {
22     /// <summary>
23     /// The marker map object.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public class Marker : MapObject, IDisposable
27     {
28         internal Interop.MarkerHandle handle;
29
30         internal Marker(Geocoordinates coordinates, string imagePath, Interop.ViewMarkerType type)
31         {
32             var err = Interop.ErrorCode.InvalidParameter;
33             if (coordinates == null || imagePath == null)
34             {
35                 err.ThrowIfFailed("given coordinates or imagePath is null");
36             }
37             handle = new Interop.MarkerHandle(coordinates.handle, imagePath, type);
38         }
39
40         /// <summary>
41         /// Destroy the Marker object.
42         /// </summary>
43         ~Marker()
44         {
45             Dispose(false);
46         }
47
48         /// <summary>
49         /// Gets or sets the clicked event handlers.
50         /// </summary>
51         /// <since_tizen> 3 </since_tizen>
52         public event EventHandler Clicked;
53
54         /// <summary>
55         /// Gets or sets the marker's visibility.
56         /// </summary>
57         /// <since_tizen> 3 </since_tizen>
58         public override bool IsVisible
59         {
60             get
61             {
62                 return handle.IsVisible;
63             }
64             set
65             {
66                 handle.IsVisible = value;
67             }
68         }
69
70         /// <summary>
71         /// Gets or sets the geographical coordinates for this marker.
72         /// </summary>
73         /// <since_tizen> 3 </since_tizen>
74         public Geocoordinates Coordinates
75         {
76             get
77             {
78                 return new Geocoordinates(handle.Coordinates);
79             }
80             set
81             {
82                 handle.Coordinates = value.handle;
83
84                 // Marker takes ownership of the native handle.
85                 value.handle.HasOwnership = false;
86             }
87         }
88
89         /// <summary>
90         /// Gets or sets a string representing the image file path for this marker.
91         /// </summary>
92         /// <since_tizen> 3 </since_tizen>
93         public string ImagePath
94         {
95             get
96             {
97                 return handle.ImageFile;
98             }
99             set
100             {
101                 handle.ImageFile = value;
102             }
103         }
104
105         /// <summary>
106         /// Gets or sets the screen size for this marker.
107         /// </summary>
108         /// <since_tizen> 3 </since_tizen>
109         public Size MarkerSize
110         {
111             get
112             {
113                 return handle.MarkerSize;
114             }
115             set
116             {
117                 handle.MarkerSize = value;
118             }
119         }
120
121         /// <summary>
122         /// Gets or sets the z-order for this marker.
123         /// </summary>
124         /// <since_tizen> 3 </since_tizen>
125         /// <value>The integer value is 0 by default, and must be in the range of -100 to 100.</value>
126         public int ZOrder
127         {
128             get
129             {
130                 return handle.ZOrder;
131             }
132             set
133             {
134                 handle.ZOrder = value;
135             }
136         }
137
138         /// <summary>
139         /// Changes the marker size.
140         /// </summary>
141         /// <since_tizen> 3 </since_tizen>
142         /// <param name="newSize">New size.</param>
143         public void Resize(Size newSize)
144         {
145             MarkerSize = newSize;
146         }
147
148         /// <summary>
149         /// Changes the marker coordinates.
150         /// </summary>
151         /// <since_tizen> 3 </since_tizen>
152         /// <param name="newPosition">New position for the marker.</param>
153         public void Move(Geocoordinates newPosition)
154         {
155             Coordinates = newPosition;
156         }
157
158         internal override void HandleClickedEvent()
159         {
160             Clicked?.Invoke(this, EventArgs.Empty);
161         }
162
163         internal override void InvalidateMapObject()
164         {
165             handle = null;
166         }
167
168         internal override Interop.ViewObjectHandle GetHandle()
169         {
170             return handle;
171         }
172
173         #region IDisposable Support
174         private bool _disposedValue = false;
175
176         /// <summary>
177         /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
178         /// </summary>
179         /// <param name="disposing">If true, managed and unmanaged resources can be disposed, otherwise only unmanaged resources can be disposed.</param>
180         protected virtual void Dispose(bool disposing)
181         {
182             if (!_disposedValue)
183             {
184                 handle?.Dispose();
185                 _disposedValue = true;
186             }
187         }
188
189         /// <summary>
190         /// Releases all the resources used by this object.
191         /// </summary>
192         /// <since_tizen> 3 </since_tizen>
193         public void Dispose()
194         {
195             Dispose(true);
196             GC.SuppressFinalize(this);
197         }
198
199
200         #endregion
201     }
202
203     /// <summary>
204     /// Pin type the marker map object.
205     /// </summary>
206     /// <since_tizen> 3 </since_tizen>
207     public class Pin : Marker
208     {
209         private const string defaultImagePath = "/usr/share/dotnet.tizen/framework/res/maps_marker_pin_48.png";
210
211         /// <summary>
212         /// Creates a pin type marker.
213         /// </summary>
214         /// <since_tizen> 3 </since_tizen>
215         /// <param name="coordinates">Marker coordinates.</param>
216         /// <exception cref="System.ArgumentException">Thrown when input coordinates are invalid.</exception>
217         public Pin(Geocoordinates coordinates)
218             : base(coordinates, defaultImagePath, Interop.ViewMarkerType.Pin)
219         {
220         }
221
222         /// <summary>
223         /// Creates a pin type marker.
224         /// </summary>
225         /// <since_tizen> 3 </since_tizen>
226         /// <param name="coordinates">Marker coordinates.</param>
227         /// <param name="imagePath">Image file path for the Marker.</param>
228         /// <remarks>
229         /// http://tizen.org/privilege/mediastorage is needed if the file path is relevant to media storage.
230         /// http://tizen.org/privilege/externalstorage is needed if the file path is relevant to external storage.
231         /// </remarks>
232         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
233         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
234         /// <exception cref="System.ArgumentException">Thrown when the input coordinates or imagePath is invalid.</exception>
235         public Pin(Geocoordinates coordinates, string imagePath)
236             : base(coordinates, imagePath, Interop.ViewMarkerType.Pin)
237         {
238         }
239     }
240
241     /// <summary>
242     /// Sticker type marker map object.
243     /// </summary>
244     /// <since_tizen> 3 </since_tizen>
245     public class Sticker : Marker
246     {
247         private const string defaultImagePath = "/usr/share/dotnet.tizen/framework/res/maps_marker_sticker_48.png";
248
249         /// <summary>
250         /// Creates a sticker type marker.
251         /// </summary>
252         /// <since_tizen> 3 </since_tizen>
253         /// <param name="coordinates">Marker coordinates.</param>
254         /// <exception cref="System.ArgumentException">Thrown when input coordinates are invalid.</exception>
255         public Sticker(Geocoordinates coordinates)
256             : base(coordinates, defaultImagePath, Interop.ViewMarkerType.Sticker)
257         {
258         }
259
260         /// <summary>
261         /// Creates a sticker type marker.
262         /// </summary>
263         /// <since_tizen> 3 </since_tizen>
264         /// <param name="coordinates">Marker coordinates.</param>
265         /// <param name="imagePath">Image file path for Marker.</param>
266         /// <remarks>
267         /// http://tizen.org/privilege/mediastorage is needed if the input or output path are relevant to media storage.
268         /// http://tizen.org/privilege/externalstorage is needed if the input or output path are relevant to external storage.
269         /// </remarks>
270         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
271         /// <exception cref="System.UnauthorizedAccessException">Thrown when application does not have some privilege to access this method.</exception>
272         /// <exception cref="System.ArgumentException">Thrown when the input coordinates or imagePath is invalid.</exception>
273         public Sticker(Geocoordinates coordinates, string imagePath)
274             : base(coordinates, imagePath, Interop.ViewMarkerType.Sticker)
275         {
276         }
277     }
278 }