[Maps] Modify diposing routines
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Tizen.Maps / Overlay.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 EvasObject = ElmSharp.EvasObject;
19
20 namespace Tizen.Maps
21 {
22     /// <summary>
23     /// Overlay map object.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public class Overlay : MapObject, IDisposable
27     {
28         internal Interop.OverlayHandle handle;
29
30         /// <summary>
31         /// Creates a normal overlay map object.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         /// <param name="coordinates"></param>
35         /// <param name="objectToContain"></param>
36         /// <exception cref="ArgumentException">Thrown when the input coordinates or objectToContain are invalid.</exception>
37         public Overlay(Geocoordinates coordinates, EvasObject objectToContain)
38             : this(coordinates, objectToContain, Interop.ViewOverlayType.Normal)
39         {
40         }
41
42         internal Overlay(Geocoordinates coordinates, EvasObject objectToContain, Interop.ViewOverlayType type)
43         {
44             var err = Interop.ErrorCode.InvalidParameter;
45             if (coordinates == null || objectToContain == null)
46             {
47                 err.ThrowIfFailed("given coordinates or parent evas object is null");
48             }
49             handle = new Interop.OverlayHandle(coordinates.handle, objectToContain, type);
50         }
51
52         /// <summary>
53         /// Destroy the Overlay object.
54         /// </summary>
55         ~Overlay()
56         {
57             Dispose(false);
58         }
59
60         /// <summary>
61         /// Gets or sets the visibility of an overlay map object.
62         /// </summary>
63         /// <since_tizen> 3 </since_tizen>
64         public override bool IsVisible
65         {
66             get { return handle.IsVisible; }
67             set { handle.IsVisible = value; }
68         }
69
70         /// <summary>
71         /// Gets or sets geographical coordinates for an overlay map object.
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                 // Overlay takes ownership of the native handle.
83                 handle.Coordinates = value.handle;
84                 value.handle.HasOwnership = false;
85             }
86         }
87
88         /// <summary>
89         /// Gets or sets minimum zoom level for an overlay map object.
90         /// </summary>
91         /// <since_tizen> 3 </since_tizen>
92         public int MinimumZoomLevel
93         {
94             get
95             {
96                 return handle.MinZoomLevel;
97             }
98             set
99             {
100                 handle.MinZoomLevel = value;
101             }
102         }
103
104         /// <summary>
105         /// Gets or sets maximum zoom lever for an overlay map object.
106         /// </summary>
107         /// <since_tizen> 3 </since_tizen>
108         public int MaximumZoomLevel
109         {
110             get
111             {
112                 return handle.MaxZoomLevel;
113             }
114             set
115             {
116                 handle.MaxZoomLevel = value;
117             }
118         }
119
120         // Overlay object does not support click events
121         internal override void HandleClickedEvent()
122         {
123             throw new NotSupportedException("Overlay object does not support click events");
124         }
125
126         internal override void InvalidateMapObject()
127         {
128             handle = null;
129         }
130
131         internal override Interop.ViewObjectHandle GetHandle()
132         {
133             return handle;
134         }
135
136         #region IDisposable Support
137         private bool _disposedValue = false;
138
139         /// <summary>
140         /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
141         /// </summary>
142         /// <param name="disposing">If true, managed and unmanaged resources can be disposed, otherwise only unmanaged resources can be disposed.</param>
143         /// <since_tizen> 3 </since_tizen>
144         protected virtual void Dispose(bool disposing)
145         {
146             if (!_disposedValue)
147             {
148                 handle?.Dispose();
149                 _disposedValue = true;
150             }
151         }
152
153         /// <summary>
154         /// Releases all the resources used by this object.
155         /// </summary>
156         /// <since_tizen> 3 </since_tizen>
157         public void Dispose()
158         {
159             Dispose(true);
160             GC.SuppressFinalize(this);
161         }
162         #endregion
163     }
164
165     /// <summary>
166     /// The bubble overlay map object.
167     /// </summary>
168     /// <since_tizen> 3 </since_tizen>
169     public class BubbleOverlay : Overlay
170     {
171         /// <summary>
172         /// Creates a bubble overlay.
173         /// </summary>
174         /// <since_tizen> 3 </since_tizen>
175         /// <param name="coordinates">The geographical coordinates to be pointed.</param>
176         /// <param name="objectToContain">The EvasObject to be shown.</param>
177         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
178         /// <exception cref="ArgumentException">Thrown when the input coordinates or objectToContain are invalid.</exception>
179         public BubbleOverlay(Geocoordinates coordinates, EvasObject objectToContain)
180             : base(coordinates, objectToContain, Interop.ViewOverlayType.Bubble)
181         {
182         }
183     }
184
185     /// <summary>
186     /// The box overlay map object.
187     /// </summary>
188     /// <since_tizen> 3 </since_tizen>
189     public class BoxOverlay : Overlay
190     {
191         /// <summary>
192         /// Creates a box overlay.
193         /// </summary>
194         /// <since_tizen> 3 </since_tizen>
195         /// <param name="coordinates">The geographical coordinates to be pointed.</param>
196         /// <param name="objectToContain">The EvasObject to be shown.</param>
197         /// <exception cref="System.NotSupportedException">Thrown when the required feature is not supported.</exception>
198         /// <exception cref="ArgumentException">Thrown when the input coordinates or objectToContain are invalid</exception>
199         public BoxOverlay(Geocoordinates coordinates, EvasObject objectToContain)
200             : base(coordinates, objectToContain, Interop.ViewOverlayType.Box)
201         {
202         }
203     }
204 }