[ACR-564] deprecate unused API
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Image.cs
old mode 100755 (executable)
new mode 100644 (file)
index 3f1bc1c..db9bb06
@@ -24,8 +24,10 @@ namespace ElmSharp
     /// <summary>
     /// The Image is a widget that allows one to load and display an image file on it,
     /// be it from a disk file or from a memory region.
-    /// Inherits Widget
+    /// Inherits Widget.
     /// </summary>
+    /// <since_tizen> preview </since_tizen>
+    [Obsolete("This has been deprecated in API12")]
     public class Image : Widget
     {
         bool _canScaleUp = true;
@@ -36,9 +38,11 @@ namespace ElmSharp
         EvasImage _imageObject = null;
 
         /// <summary>
-        /// Creates and initializes a new instance of Image class.
+        /// Creates and initializes a new instance of the Image class.
         /// </summary>
-        /// <param name="parent">The parent is a given container which will be attached by Image as a child. It's <see cref="EvasObject"/> type.</param>
+        /// <param name="parent">The parent is a given container, which will be attached by the image as a child. It's <see cref="EvasObject"/> type.</param>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public Image(EvasObject parent) : base(parent)
         {
             _clicked = new SmartEvent(this, "clicked");
@@ -48,21 +52,29 @@ namespace ElmSharp
         /// <summary>
         /// Clicked will be triggered when the image is clicked.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public event EventHandler Clicked;
 
         /// <summary>
         /// LoadingCompleted will be triggered when the image is loaded completely.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public event EventHandler LoadingCompleted;
 
         /// <summary>
-        /// Clicked will be triggered when the image is fail to load.
+        /// Clicked will be triggered when the image fails to load.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public event EventHandler LoadingFailed;
 
         /// <summary>
         /// Gets the file that is used as an image.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public string File
         {
             get
@@ -74,6 +86,8 @@ namespace ElmSharp
         /// <summary>
         /// Sets or gets the smooth effect for an image.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool IsSmooth
         {
             get
@@ -89,6 +103,8 @@ namespace ElmSharp
         /// <summary>
         /// Sets or gets whether scaling is disabled on the object.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool IsScaling
         {
             get
@@ -102,8 +118,10 @@ namespace ElmSharp
         }
 
         /// <summary>
-        /// Sets or gets whether the object is down resizeable.
+        /// Sets or gets whether the object is down resizable.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool CanScaleDown
         {
             get
@@ -118,8 +136,10 @@ namespace ElmSharp
         }
 
         /// <summary>
-        /// Sets or gets whether the object is up resizeable.
+        /// Sets or gets whether the object is up resizable.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool CanScaleUp
         {
             get
@@ -136,6 +156,8 @@ namespace ElmSharp
         /// <summary>
         /// Sets or gets whether the image fills the entire object area, when keeping the aspect ratio.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool CanFillOutside
         {
             get
@@ -151,6 +173,8 @@ namespace ElmSharp
         /// <summary>
         /// Sets or gets the prescale size for the image.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public int PrescaleSize
         {
             get
@@ -166,6 +190,8 @@ namespace ElmSharp
         /// <summary>
         /// Sets or gets whether the original aspect ratio of the image should be kept on resize.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool IsFixedAspect
         {
             get
@@ -181,6 +207,8 @@ namespace ElmSharp
         /// <summary>
         /// Sets or gets whether an image object (which supports animation) is to animate itself.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool IsAnimated
         {
             get
@@ -196,6 +224,8 @@ namespace ElmSharp
         /// <summary>
         /// Gets whether an image object supports animation.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool IsAnimatedAvailable
         {
             get
@@ -211,6 +241,8 @@ namespace ElmSharp
         /// An image object, even if it supports animation, will be displayed by default without animation.
         /// To actually start playing any image object's animation, <see cref="IsAnimated"/> should be TRUE before setting this property true.
         /// </remarks>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool IsAnimationPlaying
         {
             get
@@ -226,6 +258,8 @@ namespace ElmSharp
         /// <summary>
         /// Sets or gets whether the image is 'editable'.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool IsEditable
         {
             get
@@ -241,6 +275,8 @@ namespace ElmSharp
         /// <summary>
         /// Gets the current size of the image.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public Size ObjectSize
         {
             get
@@ -251,8 +287,10 @@ namespace ElmSharp
         }
 
         /// <summary>
-        /// Sets or gets whether alpha channel data is being used on the given image object.
+        /// Sets or gets whether the alpha channel data is being used on the given image object.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool IsOpaque
         {
             get
@@ -275,6 +313,8 @@ namespace ElmSharp
         /// <summary>
         /// Sets or gets the image orientation.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public ImageOrientation Orientation
         {
             get
@@ -288,8 +328,10 @@ namespace ElmSharp
         }
 
         /// <summary>
-        /// Sets or gets the image color
+        /// Sets or gets the image color.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public override Color Color
         {
             get
@@ -314,8 +356,10 @@ namespace ElmSharp
         }
 
         /// <summary>
-        /// Sets the background color
+        /// Sets the background color.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public override Color BackgroundColor
         {
             set
@@ -336,7 +380,9 @@ namespace ElmSharp
         /// Gets the inlined image object of the image widget.
         /// This property allows one to get the underlying EvasObject of type Image from this elementary widget. It can be useful to do things like save the image to a file, etc.
         /// </summary>
-        /// <remarks>Be careful to not manipulate it, as it is under the control of widget.</remarks>
+        /// <remarks>Be careful not to manipulate it, as it is under the control of the widget.</remarks>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public EvasImage ImageObject
         {
             get
@@ -345,7 +391,10 @@ namespace ElmSharp
                 {
                     IntPtr evasObj = Interop.Elementary.elm_image_object_get(RealHandle);
                     if (evasObj != IntPtr.Zero)
+                    {
                         _imageObject = new EvasImage(this, evasObj);
+                        _imageObject.Deleted += (s, e) => _imageObject = null;
+                    }
                 }
                 return _imageObject;
             }
@@ -354,10 +403,12 @@ namespace ElmSharp
         /// <summary>
         /// Sets the dimensions for an image object's border, a region which is not scaled together with its center ever.
         /// </summary>
-        /// <param name="left">The border's left width</param>
-        /// <param name="right">The border's right width</param>
-        /// <param name="top">The border's top width</param>
-        /// <param name="bottom">The border's bottom width</param>
+        /// <param name="left">The border's left width.</param>
+        /// <param name="right">The border's right width.</param>
+        /// <param name="top">The border's top width.</param>
+        /// <param name="bottom">The border's bottom width.</param>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public void SetBorder(int left, int right, int top, int bottom)
         {
             ImageObject?.SetBorder(left, right, top, bottom);
@@ -371,6 +422,8 @@ namespace ElmSharp
         /// This function sets if the center part of the scaled image is to be drawn or left completely blank, or forced to be solid.
         /// Very useful for frames and decorations.
         /// </remarks>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public ImageBorderFillMode BorderCenterFillMode
         {
             get
@@ -397,12 +450,14 @@ namespace ElmSharp
         /// <summary>
         /// Sets the file that is used as the image's source.
         /// </summary>
-        /// <param name="file">The path to the file that is used as an image source</param>
+        /// <param name="file">The path to the file that is used as an image source.</param>
         /// <returns>(true = success, false = error)</returns>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool Load(string file)
         {
             if (file == null)
-                throw new ArgumentNullException("file");
+                throw new ArgumentNullException(nameof(file));
 
             Interop.Elementary.elm_image_async_open_set(RealHandle, false);
             Interop.Elementary.elm_image_preload_disabled_set(RealHandle, true);
@@ -410,14 +465,16 @@ namespace ElmSharp
         }
 
         /// <summary>
-        /// Sets the uri that is used as the image's source.
+        /// Sets the URI that is used as the image's source.
         /// </summary>
-        /// <param name="uri">The uri to the file that is used as an image source</param>
+        /// <param name="uri">The URI to the file that is used as an image source.</param>
         /// <returns>(true = success, false = error)</returns>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool Load(Uri uri)
         {
             if (uri == null)
-                throw new ArgumentNullException("uri");
+                throw new ArgumentNullException(nameof(uri));
 
             return Load(uri.IsFile ? uri.LocalPath : uri.AbsoluteUri);
         }
@@ -426,18 +483,19 @@ namespace ElmSharp
         /// Sets a location in the memory to be used as an image object's source bitmap.
         /// </summary>
         /// <remarks>
-        /// This function is handy when the contents of an image file are mapped into the memory, for example.
-        /// The format string should be something like "png", "jpg", "tga", "tiff", "bmp" etc, when provided (null, on the contrary).
+        /// This function is handy when the contents of an image file are mapped into the memory, for example,
+        /// the format string should be something like "png", "jpg", "tga", "tiff", "bmp" etc, when provided (null, on the contrary).
         /// This improves the loader performance as it tries the "correct" loader first, before trying a range of other possible loaders until one succeeds.
         /// </remarks>
-        /// <param name="img">The binary data that is used as an image source</param>
-        /// <param name="size">The size of the binary data blob img</param>
+        /// <param name="img">The binary data that is used as an image source.</param>
+        /// <param name="size">The size of the binary data blob img.</param>
         /// <returns>(true = success, false = error)</returns>
+        /// <since_tizen> preview </since_tizen>
         [Obsolete("This method will be removed. Use Load(Stream stream) instead.")]
         public unsafe bool Load(byte* img, long size)
         {
             if (img == null)
-                throw new ArgumentNullException("img");
+                throw new ArgumentNullException(nameof(img));
 
             Interop.Elementary.elm_image_async_open_set(RealHandle, false);
             Interop.Elementary.elm_image_preload_disabled_set(RealHandle, true);
@@ -447,12 +505,14 @@ namespace ElmSharp
         /// <summary>
         /// Sets the stream that is used as the image's source.
         /// </summary>
-        /// <param name="stream">The stream that is used as an image source</param>
+        /// <param name="stream">The stream that is used as an image source.</param>
         /// <returns>(true = success, false = error)</returns>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public bool Load(Stream stream)
         {
             if (stream == null)
-                throw new ArgumentNullException("stream");
+                throw new ArgumentNullException(nameof(stream));
 
             Interop.Elementary.elm_image_async_open_set(RealHandle, false);
             Interop.Elementary.elm_image_preload_disabled_set(RealHandle, true);
@@ -471,13 +531,15 @@ namespace ElmSharp
         /// <summary>
         /// Sets the file that is used as the image's source with async.
         /// </summary>
-        /// <param name="file">The path to the file that is used as an image source</param>
-        /// <param name="cancellationToken">cancellation token</param>
+        /// <param name="file">The path to the file that is used as an image source.</param>
+        /// <param name="cancellationToken">The cancellation token.</param>
         /// <returns>(true = success, false = error)</returns>
-        public Task<bool> LoadAsync(string file, CancellationToken cancellationToken = default(CancellationToken))
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
+        public async Task<bool> LoadAsync(string file, CancellationToken cancellationToken = default(CancellationToken))
         {
             if (file == null)
-                throw new ArgumentNullException("file");
+                throw new ArgumentNullException(nameof(file));
 
             Interop.Elementary.elm_image_async_open_set(RealHandle, true);
             Interop.Elementary.elm_image_preload_disabled_set(RealHandle, false);
@@ -495,7 +557,6 @@ namespace ElmSharp
             SmartEvent loadReady = new SmartEvent(this, RealHandle, "load,ready");
             loadReady.On += (s, e) =>
             {
-                loadReady.Dispose();
                 LoadingCompleted?.Invoke(this, EventArgs.Empty);
                 if (tcs != null && !tcs.Task.IsCompleted)
                 {
@@ -506,7 +567,6 @@ namespace ElmSharp
             SmartEvent loadError = new SmartEvent(this, RealHandle, "load,error");
             loadError.On += (s, e) =>
             {
-                loadError.Dispose();
                 LoadingFailed?.Invoke(this, EventArgs.Empty);
                 if (tcs != null && !tcs.Task.IsCompleted)
                 {
@@ -514,25 +574,31 @@ namespace ElmSharp
                 }
             };
 
-            bool ret = Interop.Elementary.elm_image_file_set(RealHandle, file, null);
-            if (!ret)
+            using (loadReady)
+            using (loadError)
             {
-                throw new InvalidOperationException("Failed to set file to Image");
+                bool ret = Interop.Elementary.elm_image_file_set(RealHandle, file, null);
+                if (!ret)
+                {
+                    throw new InvalidOperationException("Failed to set file to Image");
+                }
+                // it should be return on main thread, because SmartEvent should be disposed on main thread
+                return await tcs.Task.ConfigureAwait(true);
             }
-
-            return tcs.Task;
         }
 
         /// <summary>
-        /// Sets the uri that is used as the image's source with async.
+        /// Sets the URI that is used as the image's source with async.
         /// </summary>
-        /// <param name="uri">The uri to the file that is used as an image source</param>
-        /// <param name="cancellationToken">cancellation token</param>
+        /// <param name="uri">The URI to the file that is used as an image source.</param>
+        /// <param name="cancellationToken">The cancellation token.</param>
         /// <returns>(true = success, false = error)</returns>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public Task<bool> LoadAsync(Uri uri, CancellationToken cancellationToken = default(CancellationToken))
         {
             if (uri == null)
-                throw new ArgumentNullException("uri");
+                throw new ArgumentNullException(nameof(uri));
 
             return LoadAsync(uri.IsFile ? uri.LocalPath : uri.AbsoluteUri, cancellationToken);
         }
@@ -540,13 +606,15 @@ namespace ElmSharp
         /// <summary>
         /// Sets the stream that is used as the image's source with async.
         /// </summary>
-        /// <param name="stream">The stream that is used as an image source</param>
-        /// <param name="cancellationToken">cancellation token</param>
+        /// <param name="stream">The stream that is used as an image source.</param>
+        /// <param name="cancellationToken">The cancellation token.</param>
         /// <returns>(true = success, false = error)</returns>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public async Task<bool> LoadAsync(Stream stream, CancellationToken cancellationToken = default(CancellationToken))
         {
             if (stream == null)
-                throw new ArgumentNullException("stream");
+                throw new ArgumentNullException(nameof(stream));
 
             Interop.Elementary.elm_image_async_open_set(RealHandle, true);
             Interop.Elementary.elm_image_preload_disabled_set(RealHandle, false);
@@ -564,7 +632,6 @@ namespace ElmSharp
             SmartEvent loadReady = new SmartEvent(this, RealHandle, "load,ready");
             loadReady.On += (s, e) =>
             {
-                loadReady.Dispose();
                 LoadingCompleted?.Invoke(this, EventArgs.Empty);
                 if (tcs != null && !tcs.Task.IsCompleted)
                 {
@@ -575,7 +642,6 @@ namespace ElmSharp
             SmartEvent loadError = new SmartEvent(this, RealHandle, "load,error");
             loadError.On += (s, e) =>
             {
-                loadError.Dispose();
                 LoadingFailed?.Invoke(this, EventArgs.Empty);
                 if (tcs != null && !tcs.Task.IsCompleted)
                 {
@@ -583,32 +649,36 @@ namespace ElmSharp
                 }
             };
 
-            MemoryStream memstream = new MemoryStream();
-            await stream.CopyToAsync(memstream);
-
-            unsafe
+            using (MemoryStream memstream = new MemoryStream())
+            using (loadReady)
+            using (loadError)
             {
-                byte[] dataArr = memstream.ToArray();
-                fixed (byte* data = &dataArr[0])
+                await stream.CopyToAsync(memstream).ConfigureAwait(true);
+
+                unsafe
                 {
-                    bool ret = Interop.Elementary.elm_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);
-                    if (!ret)
+                    byte[] dataArr = memstream.ToArray();
+                    fixed (byte* data = &dataArr[0])
                     {
-                        return false;
+                        bool ret = Interop.Elementary.elm_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);
+                        if (!ret)
+                        {
+                            return false;
+                        }
                     }
                 }
+                // it should be return on main thread, because SmartEvent should be disposed on main thread
+                return await tcs.Task.ConfigureAwait(true);
             }
-
-            memstream.Dispose();
-
-            return await tcs.Task;
         }
 
         /// <summary>
-        /// Sets the color of color class for a given widget.
+        /// Sets the color of the Color class for a given widget.
         /// </summary>
-        /// <param name="part">The name of color class.</param>
-        /// <param name="color">The struct of color</param>
+        /// <param name="part">The name of the Color class.</param>
+        /// <param name="color">The struct of the Color class.</param>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public override void SetPartColor(string part, Color color)
         {
             Interop.Elementary.elm_object_color_class_color_set(Handle, part, color.R * color.A / 255,
@@ -618,10 +688,12 @@ namespace ElmSharp
         }
 
         /// <summary>
-        /// Gets the color of color class for a given widget.
+        /// Gets the color of the Color class for a given widget.
         /// </summary>
-        /// <param name="part">The name of color class.</param>
-        /// <returns>color object</returns>
+        /// <param name="part">The name of the Color class.</param>
+        /// <returns>The color object.</returns>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public override Color GetPartColor(string part)
         {
             Interop.Elementary.elm_object_color_class_color_get(Handle, part, out int r, out int g, out int b, out int a);
@@ -631,11 +703,13 @@ namespace ElmSharp
         /// <summary>
         /// Sets the content at a part of a given container widget.
         /// </summary>
-        /// <param name="parent">The parent is a given container which will be attached by Image as a child. It's <see cref="EvasObject"/> type.</param>
-        /// <returns>The new object, otherwise null if it cannot be created</returns>
+        /// <param name="parent">The parent is a given container, which will be attached by the image as a child. It's <see cref="EvasObject"/> type.</param>
+        /// <returns>The new object, otherwise null if it cannot be created.</returns>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         protected override IntPtr CreateHandle(EvasObject parent)
         {
-            IntPtr handle = Interop.Elementary.elm_layout_add(parent);
+            IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
             Interop.Elementary.elm_layout_theme_set(handle, "layout", "background", "default");
 
             RealHandle = Interop.Elementary.elm_image_add(handle);
@@ -646,69 +720,73 @@ namespace ElmSharp
     }
 
     /// <summary>
-    /// Enumeration for the fill mode of image border
+    /// Enumeration for the fill mode of the image border.
     /// </summary>
+    /// <since_tizen> preview </since_tizen>
+    [Obsolete("This has been deprecated in API12")]
     public enum ImageBorderFillMode
     {
         /// <summary>
-        /// None mode of image border
+        /// None mode of the image border.
         /// </summary>
         None,
 
         /// <summary>
-        /// Default mode of image border
+        /// Default mode of the image border.
         /// </summary>
         Default,
 
         /// <summary>
-        /// Solid mode of image border
+        /// Solid mode of the image border.
         /// </summary>
         Solid,
     }
 
     /// <summary>
-    /// Enumeration for the possible orientation options
+    /// Enumeration for the possible orientation options.
     /// </summary>
+    /// <since_tizen> preview </since_tizen>
+    [Obsolete("This has been deprecated in API12")]
     public enum ImageOrientation : int
     {
         /// <summary>
-        /// No orientation change
+        /// No orientation change.
         /// </summary>
         None = 0,
 
         /// <summary>
-        /// Rotate 90 degrees clockwise
+        /// Rotate 90 degrees clockwise.
         /// </summary>
         Rotate90,
 
         /// <summary>
-        /// Rotate 180 degrees clockwise
+        /// Rotate 180 degrees clockwise.
         /// </summary>
         Rotate180,
 
         /// <summary>
-        /// Rotate 90 degrees counter-clockwise (i.e. 270 degrees clockwise)
+        /// Rotate 90 degrees counter-clockwise (i.e., 270 degrees clockwise).
         /// </summary>
         Rotate270,
 
         /// <summary>
-        /// Flip image horizontally
+        /// Flip the image horizontally.
         /// </summary>
         FlipHorizontal,
 
         /// <summary>
-        /// Flip image vertically
+        /// Flip the image vertically.
         /// </summary>
         FlipVertical,
 
         /// <summary>
-        /// Flip the image along the y = (width - x) line (bottom-left to top-right)
+        /// Flip the image along the Y = (width - X) line (bottom-left to top-right).
         /// </summary>
         FlipTranspose,
 
         /// <summary>
-        /// Flip the image along the y = x line (top-left to bottom-right)
+        /// Flip the image along the Y = X line (top-left to bottom-right).
         /// </summary>
         FlipTransverse
     }
-}
\ No newline at end of file
+}