[NUI] Add CursorPositionChanged Event (#3400)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ImageView.cs
1 /*
2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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 System.ComponentModel;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.BaseComponents
23 {
24
25     /// <summary>
26     /// ImageView is a class for displaying an image resource.<br />
27     /// An instance of ImageView can be created using a URL or an image instance.<br />
28     /// </summary>
29     /// <since_tizen> 3 </since_tizen>
30     public class ImageView : View
31     {
32         static ImageView() { }
33
34         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
35         [EditorBrowsable(EditorBrowsableState.Never)]
36         public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create(nameof(ImageView.ResourceUrl), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
37         {
38             var imageView = (ImageView)bindable;
39
40             if (newValue is Selector<string> selector)
41             {
42                 imageView.ResourceUrlSelector = selector;
43             }
44             else
45             {
46                 imageView.resourceUrlSelector?.Reset(imageView);
47                 imageView.SetResourceUrl((string)newValue);
48             }
49         },
50         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
51         {
52             var imageView = (ImageView)bindable;
53             string ret = "";
54
55             PropertyMap imageMap = new PropertyMap();
56             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
57             imageMap.Find(ImageVisualProperty.URL)?.Get(out ret);
58             return ret;
59         }));
60
61         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
62         [EditorBrowsable(EditorBrowsableState.Never)]
63         public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(ImageView.Image), typeof(PropertyMap), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
64         {
65             var imageView = (ImageView)bindable;
66             if (newValue != null)
67             {
68                 PropertyMap map = (PropertyMap)newValue;
69                 if (imageView.IsCreateByXaml)
70                 {
71                     string url = "", alphaMaskURL = "", auxiliaryImageURL = "";
72                     string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
73                     PropertyValue urlValue = map.Find(NDalic.ImageVisualUrl);
74                     bool ret = false;
75                     if (urlValue != null) ret = urlValue.Get(out url);
76                     PropertyMap mmap = new PropertyMap();
77                     if (ret && url.StartsWith("*Resource*"))
78                     {
79                         url = url.Replace("*Resource*", resource);
80                         mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(url));
81                     }
82
83                     ret = false;
84                     PropertyValue alphaMaskUrlValue = map.Find(NDalic.ImageVisualAlphaMaskUrl);
85                     if (alphaMaskUrlValue != null) ret = alphaMaskUrlValue.Get(out alphaMaskURL);
86                     if (ret && alphaMaskURL.StartsWith("*Resource*"))
87                     {
88                         alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource);
89                         mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(alphaMaskURL));
90                     }
91
92                     ret = false;
93                     PropertyValue auxiliaryImageURLValue = map.Find(NDalic.ImageVisualAuxiliaryImageUrl);
94                     if (auxiliaryImageURLValue != null) ret = auxiliaryImageURLValue.Get(out auxiliaryImageURL);
95                     if (ret && auxiliaryImageURL.StartsWith("*Resource*"))
96                     {
97                         auxiliaryImageURL = auxiliaryImageURL.Replace("*Resource*", resource);
98                         mmap.Insert(NDalic.ImageVisualAuxiliaryImageUrl, new PropertyValue(auxiliaryImageURL));
99                     }
100
101                     map.Merge(mmap);
102                 }
103                 if (imageView._border == null)
104                 {
105                     Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
106                 }
107             }
108         }),
109         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
110         {
111             var imageView = (ImageView)bindable;
112             if (imageView._border == null)
113             {
114                 PropertyMap temp = new PropertyMap();
115                 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(temp);
116                 return temp;
117             }
118             else
119             {
120                 return null;
121             }
122         }));
123
124         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
125         [EditorBrowsable(EditorBrowsableState.Never)]
126         public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create(nameof(PreMultipliedAlpha), typeof(bool), typeof(ImageView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
127         {
128             var imageView = (ImageView)bindable;
129             if (newValue != null)
130             {
131                 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, new Tizen.NUI.PropertyValue((bool)newValue));
132             }
133         }),
134         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
135         {
136             var imageView = (ImageView)bindable;
137             bool temp = false;
138             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha).Get(out temp);
139             return temp;
140         }));
141
142         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
143         [EditorBrowsable(EditorBrowsableState.Never)]
144         public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
145         {
146             var imageView = (ImageView)bindable;
147             if (newValue != null)
148             {
149                 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
150             }
151         }),
152         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
153         {
154             var imageView = (ImageView)bindable;
155             Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
156             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea).Get(temp);
157             RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
158             return relativeTemp;
159         }));
160
161         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
162         [EditorBrowsable(EditorBrowsableState.Never)]
163         public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
164         {
165             var imageView = (ImageView)bindable;
166             imageView.borderSelector?.Reset(imageView);
167
168             if (newValue is Selector<Rectangle> selector)
169             {
170                 if (selector.HasAll()) imageView.SetBorder(selector.All);
171                 else imageView.borderSelector = new TriggerableSelector<Rectangle>(imageView, selector, imageView.SetBorder, true);
172             }
173             else
174             {
175                 imageView.SetBorder((Rectangle)newValue);
176             }
177         },
178         defaultValueCreator: (bindable) =>
179         {
180             var imageView = (ImageView)bindable;
181             return imageView._border;
182         });
183
184         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
185         [EditorBrowsable(EditorBrowsableState.Never)]
186         public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
187         {
188             var imageView = (ImageView)bindable;
189             if (newValue != null)
190             {
191                 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
192             }
193         },
194         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
195         {
196             var imageView = (ImageView)bindable;
197             bool ret = false;
198             PropertyMap imageMap = new PropertyMap();
199             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
200             imageMap.Find(ImageVisualProperty.BorderOnly)?.Get(out ret);
201             return ret;
202         }));
203
204         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
205         [EditorBrowsable(EditorBrowsableState.Never)]
206         public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronosLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
207         {
208             var imageView = (ImageView)bindable;
209             if (newValue != null)
210             {
211                 imageView._synchronosLoading = (bool)newValue;
212                 imageView.UpdateImage(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
213             }
214         },
215         defaultValueCreator: (bindable) =>
216         {
217             var imageView = (ImageView)bindable;
218             return imageView._synchronosLoading;
219         });
220
221         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
222         [EditorBrowsable(EditorBrowsableState.Never)]
223         public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
224         {
225             var imageView = (ImageView)bindable;
226             if (newValue != null)
227             {
228                 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
229             }
230         },
231         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
232         {
233             var imageView = (ImageView)bindable;
234
235             bool ret = false;
236             PropertyMap imageMap = new PropertyMap();
237             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
238             imageMap?.Find(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
239
240             return ret;
241         }));
242
243         private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
244         private ResourceReadyEventCallbackType _resourceReadyEventCallback;
245         private EventHandler<ResourceLoadedEventArgs> _resourceLoadedEventHandler;
246         private _resourceLoadedCallbackType _resourceLoadedCallback;
247
248         private Rectangle _border;
249         private string _resourceUrl = "";
250         private bool _synchronosLoading = false;
251         private string _alphaMaskUrl = null;
252         private int _desired_width = -1;
253         private int _desired_height = -1;
254         private VisualFittingModeType _fittingMode = VisualFittingModeType.Fill;
255         private TriggerableSelector<string> resourceUrlSelector;
256         private TriggerableSelector<Rectangle> borderSelector;
257
258         /// <summary>
259         /// Creates an initialized ImageView.
260         /// </summary>
261         /// <since_tizen> 3 </since_tizen>
262         public ImageView() : this(Interop.ImageView.New(), true)
263         {
264             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265         }
266
267         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
268         [EditorBrowsable(EditorBrowsableState.Never)]
269         public ImageView(ViewStyle viewStyle) : this(Interop.ImageView.New(), true, viewStyle)
270         {
271         }
272
273         /// <summary>
274         /// Creates an initialized ImageView with setting the status of shown or hidden.
275         /// </summary>
276         /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
277         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
278         [EditorBrowsable(EditorBrowsableState.Never)]
279         public ImageView(bool shown) : this(Interop.ImageView.New(), true)
280         {
281             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282             SetVisible(shown);
283         }
284
285         /// <summary>
286         /// Creates an initialized ImageView from a URL to an image resource.<br />
287         /// If the string is empty, ImageView will not display anything.<br />
288         /// </summary>
289         /// <param name="url">The URL of the image resource to display.</param>
290         /// <since_tizen> 3 </since_tizen>
291         public ImageView(string url) : this(Interop.ImageView.New(url), true)
292         {
293             ResourceUrl = url;
294             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295
296         }
297
298         /// <summary>
299         /// Creates an initialized ImageView from a URL to an image resource with setting shown or hidden.
300         /// </summary>
301         /// <param name="url">The URL of the image resource to display.</param>
302         /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
303         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
304         [EditorBrowsable(EditorBrowsableState.Never)]
305         public ImageView(string url, bool shown) : this(Interop.ImageView.New(url), true)
306         {
307             ResourceUrl = url;
308             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309             SetVisible(shown);
310         }
311
312         internal ImageView(string url, Uint16Pair size, bool shown = true) : this(Interop.ImageView.New(url, Uint16Pair.getCPtr(size)), true)
313         {
314             ResourceUrl = url;
315             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316
317             if (!shown)
318             {
319                 SetVisible(false);
320             }
321         }
322
323         internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle)
324         {
325             if (!shown)
326             {
327                 SetVisible(false);
328             }
329         }
330
331         internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
332         {
333             if (!shown)
334             {
335                 SetVisible(false);
336             }
337         }
338
339         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
340         private delegate void ResourceReadyEventCallbackType(IntPtr data);
341         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
342         private delegate void _resourceLoadedCallbackType(IntPtr view);
343
344         /// <summary>
345         /// An event for ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
346         /// This signal is emitted after all resources required by a control are loaded and ready.<br />
347         /// Most resources are only loaded when the control is placed on the stage.<br />
348         /// </summary>
349         /// <since_tizen> 3 </since_tizen>
350         public event EventHandler<ResourceReadyEventArgs> ResourceReady
351         {
352             add
353             {
354                 if (_resourceReadyEventHandler == null)
355                 {
356                     _resourceReadyEventCallback = OnResourceReady;
357                     ViewResourceReadySignal resourceReadySignal = ResourceReadySignal(this);
358                     resourceReadySignal?.Connect(_resourceReadyEventCallback);
359                     resourceReadySignal?.Dispose();
360                 }
361
362                 _resourceReadyEventHandler += value;
363             }
364
365             remove
366             {
367                 _resourceReadyEventHandler -= value;
368
369                 ViewResourceReadySignal resourceReadySignal = ResourceReadySignal(this);
370                 if (_resourceReadyEventHandler == null && resourceReadySignal?.Empty() == false)
371                 {
372                     resourceReadySignal?.Disconnect(_resourceReadyEventCallback);
373                 }
374                 resourceReadySignal?.Dispose();
375             }
376         }
377
378         internal event EventHandler<ResourceLoadedEventArgs> ResourceLoaded
379         {
380             add
381             {
382                 if (_resourceLoadedEventHandler == null)
383                 {
384                     _resourceLoadedCallback = OnResourceLoaded;
385                     ViewResourceReadySignal resourceReadySignal = this.ResourceReadySignal(this);
386                     resourceReadySignal?.Connect(_resourceLoadedCallback);
387                     resourceReadySignal?.Dispose();
388                 }
389
390                 _resourceLoadedEventHandler += value;
391             }
392             remove
393             {
394                 _resourceLoadedEventHandler -= value;
395                 ViewResourceReadySignal resourceReadySignal = this.ResourceReadySignal(this);
396                 if (_resourceLoadedEventHandler == null && resourceReadySignal?.Empty() == false)
397                 {
398                     resourceReadySignal?.Disconnect(_resourceLoadedCallback);
399                 }
400                 resourceReadySignal?.Dispose();
401             }
402         }
403
404         /// <summary>
405         /// Enumeration for LoadingStatus of image.
406         /// </summary>
407         /// <since_tizen> 5 </since_tizen>
408         public enum LoadingStatusType
409         {
410             /// <summary>
411             /// Loading preparing status.
412             /// </summary>
413             /// <since_tizen> 5 </since_tizen>
414             Preparing,
415             /// <summary>
416             /// Loading ready status.
417             /// </summary>
418             /// <since_tizen> 5 </since_tizen>
419             Ready,
420             /// <summary>
421             /// Loading failed status.
422             /// </summary>
423             /// <since_tizen> 5 </since_tizen>
424             Failed
425         }
426
427         /// <summary>
428         /// ImageView ResourceUrl, type string.
429         /// This is one of mandatory property. Even if not set or null set, it sets empty string ("") internally.
430         /// When it is set as null, it gives empty string ("") to be read.
431         /// </summary>
432         /// <since_tizen> 3 </since_tizen>
433         public string ResourceUrl
434         {
435             get
436             {
437                 return (string)GetValue(ResourceUrlProperty);
438             }
439             set
440             {
441                 SetValue(ResourceUrlProperty, value);
442                 NotifyPropertyChanged();
443             }
444         }
445
446         /// <summary>
447         /// This will be deprecated, please use Image instead. <br />
448         /// ImageView ImageMap, type PropertyMap: string if it is a URL, map otherwise.
449         /// </summary>
450         /// <since_tizen> 3 </since_tizen>
451         [Obsolete("Please do not use! This will be deprecated! Please use Image property instead!")]
452         [EditorBrowsable(EditorBrowsableState.Never)]
453         public PropertyMap ImageMap
454         {
455             get
456             {
457                 if (_border == null)
458                 {
459                     PropertyMap returnValue = new PropertyMap();
460                     PropertyValue image = GetProperty(ImageView.Property.IMAGE);
461                     image?.Get(returnValue);
462                     image?.Dispose();
463                     return returnValue;
464                 }
465                 else
466                 {
467                     return null;
468                 }
469             }
470             set
471             {
472                 if (_border == null)
473                 {
474                     PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
475                     SetProperty(ImageView.Property.IMAGE, setValue);
476                     NotifyPropertyChanged();
477                     setValue?.Dispose();
478                 }
479             }
480         }
481
482         /// <summary>
483         /// ImageView Image, type PropertyMap
484         /// </summary>
485         /// <since_tizen> 4 </since_tizen>
486         public PropertyMap Image
487         {
488             get
489             {
490                 if (_border == null)
491                 {
492                     return (PropertyMap)GetValue(ImageProperty);
493                 }
494                 else
495                 {
496                     return null;
497                 }
498             }
499             set
500             {
501                 if (_border == null)
502                 {
503                     SetValue(ImageProperty, value);
504                     NotifyPropertyChanged();
505                 }
506             }
507         }
508
509         /// <summary>
510         /// ImageView PreMultipliedAlpha, type Boolean.<br />
511         /// Image must be initialized.<br />
512         /// </summary>
513         /// <since_tizen> 3 </since_tizen>
514         public bool PreMultipliedAlpha
515         {
516             get
517             {
518                 return (bool)GetValue(PreMultipliedAlphaProperty);
519             }
520             set
521             {
522                 SetValue(PreMultipliedAlphaProperty, value);
523                 NotifyPropertyChanged();
524             }
525         }
526
527         /// <summary>
528         /// ImageView PixelArea, type Vector4 (Animatable property).<br />
529         /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br />
530         /// </summary>
531         /// <remarks>
532         /// The property cascade chaining set is possible. For example, this (imageView.PixelArea.X = 0.1f;) is possible.
533         /// </remarks>
534         /// <since_tizen> 3 </since_tizen>
535         public RelativeVector4 PixelArea
536         {
537             get
538             {
539                 RelativeVector4 temp = (RelativeVector4)GetValue(PixelAreaProperty);
540                 return new RelativeVector4(OnPixelAreaChanged, temp.X, temp.Y, temp.Z, temp.W);
541             }
542             set
543             {
544                 SetValue(PixelAreaProperty, value);
545                 NotifyPropertyChanged();
546             }
547         }
548
549         /// <summary>
550         /// The border of the image in the order: left, right, bottom, top.<br />
551         /// If set, ImageMap will be ignored.<br />
552         /// For N-Patch images only.<br />
553         /// Optional.
554         /// </summary>
555         /// <remarks>
556         /// The property cascade chaining set is possible. For example, this (imageView.Border.X = 1;) is possible.
557         /// </remarks>
558         /// <since_tizen> 3 </since_tizen>
559         public Rectangle Border
560         {
561             get
562             {
563                 Rectangle temp = (Rectangle)GetValue(BorderProperty);
564                 if (null == temp)
565                 {
566                     return null;
567                 }
568                 else
569                 {
570                     return new Rectangle(OnBorderChanged, temp.X, temp.Y, temp.Width, temp.Height);
571                 }
572             }
573             set
574             {
575                 SetValue(BorderProperty, value);
576                 NotifyPropertyChanged();
577             }
578         }
579
580         /// <summary>
581         /// Gets or sets whether to draw the borders only (if true).<br />
582         /// If not specified, the default is false.<br />
583         /// For N-Patch images only.<br />
584         /// Optional.
585         /// </summary>
586         /// <since_tizen> 3 </since_tizen>
587         public bool BorderOnly
588         {
589             get
590             {
591                 return (bool)GetValue(BorderOnlyProperty);
592             }
593             set
594             {
595                 SetValue(BorderOnlyProperty, value);
596                 NotifyPropertyChanged();
597             }
598         }
599
600         /// <summary>
601         /// Gets or sets whether to synchronous loading the resourceurl of image.<br />
602         /// </summary>
603         /// <since_tizen> 3 </since_tizen>
604         public bool SynchronosLoading
605         {
606             get
607             {
608                 return (bool)GetValue(SynchronosLoadingProperty);
609             }
610             set
611             {
612                 SetValue(SynchronosLoadingProperty, value);
613                 NotifyPropertyChanged();
614             }
615         }
616
617         /// <summary>
618         /// Gets or sets whether to automatically correct the orientation of an image.<br />
619         /// </summary>
620         /// <since_tizen> 5 </since_tizen>
621         public bool OrientationCorrection
622         {
623             get
624             {
625                 return (bool)GetValue(OrientationCorrectionProperty);
626             }
627             set
628             {
629                 SetValue(OrientationCorrectionProperty, value);
630                 NotifyPropertyChanged();
631             }
632         }
633
634         /// <summary>
635         /// Gets the loading state of the visual resource.
636         /// </summary>
637         /// <since_tizen> 5 </since_tizen>
638         public ImageView.LoadingStatusType LoadingStatus
639         {
640             get
641             {
642                 return (ImageView.LoadingStatusType)Interop.View.GetVisualResourceStatus(SwigCPtr, (int)Property.IMAGE);
643             }
644         }
645
646         /// <summary>
647         /// Downcasts a handle to imageView handle.
648         /// </summary>
649         /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
650         /// Please do not use! this will be deprecated!
651         /// Instead please use as keyword.
652         /// <since_tizen> 3 </since_tizen>
653         [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
654         "Like: " +
655         "BaseHandle handle = new ImageView(imagePath); " +
656         "ImageView image = handle as ImageView")]
657         [EditorBrowsable(EditorBrowsableState.Never)]
658         public static ImageView DownCast(BaseHandle handle)
659         {
660             if (null == handle)
661             {
662                 throw new ArgumentNullException(nameof(handle));
663             }
664             ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
665             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
666             return ret;
667         }
668
669         /// <summary>
670         /// Sets this ImageView from the given URL.<br />
671         /// If the URL is empty, ImageView will not display anything.<br />
672         /// </summary>
673         /// <param name="url">The URL to the image resource to display.</param>
674         /// <exception cref="ArgumentNullException"> Thrown when url is null. </exception>
675         /// <since_tizen> 3 </since_tizen>
676         public void SetImage(string url)
677         {
678             if (null == url)
679             {
680                 throw new ArgumentNullException(nameof(url));
681             }
682
683             if (url.Contains(".json"))
684             {
685                 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
686                 return;
687             }
688
689             Interop.ImageView.SetImage(SwigCPtr, url);
690             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
691
692             ResourceUrl = url;
693         }
694
695         /// <summary>
696         /// Queries if all resources required by a control are loaded and ready.<br />
697         /// Most resources are only loaded when the control is placed on the stage.<br />
698         /// True if the resources are loaded and ready, false otherwise.<br />
699         /// </summary>
700         /// <since_tizen> 3 </since_tizen>
701         public new bool IsResourceReady()
702         {
703             bool ret = Interop.View.IsResourceReady(SwigCPtr);
704             if (NDalicPINVOKE.SWIGPendingException.Pending)
705                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
706             return ret;
707         }
708
709         /// <summary>
710         /// Forcefully reloads the image. All the visuals using this image will reload to the latest image.
711         /// </summary>
712         /// <since_tizen> 5 </since_tizen>
713         public void Reload()
714         {
715             PropertyValue attributes = new PropertyValue(0);
716             this.DoAction(ImageView.Property.IMAGE, Property.ActionReload, attributes);
717             attributes?.Dispose();
718         }
719
720         /// <summary>
721         /// Plays the animated GIF. This is also the default playback mode.
722         /// </summary>
723         /// <since_tizen> 5 </since_tizen>
724         public void Play()
725         {
726             PropertyValue attributes = new PropertyValue(0);
727             this.DoAction(ImageView.Property.IMAGE, Property.ActionPlay, attributes);
728             attributes?.Dispose();
729         }
730
731         /// <summary>
732         /// Pauses the animated GIF.
733         /// </summary>
734         /// <since_tizen> 5 </since_tizen>
735         public void Pause()
736         {
737             PropertyValue attributes = new PropertyValue(0);
738             this.DoAction(ImageView.Property.IMAGE, Property.ActionPause, attributes);
739             attributes?.Dispose();
740         }
741
742         /// <summary>
743         /// Stops the animated GIF.
744         /// </summary>
745         /// <since_tizen> 5 </since_tizen>
746         public void Stop()
747         {
748             PropertyValue attributes = new PropertyValue(0);
749             this.DoAction(ImageView.Property.IMAGE, Property.ActionStop, attributes);
750             attributes?.Dispose();
751         }
752
753         /// <summary>
754         /// Gets or sets the URL of the alpha mask.<br />
755         /// Optional.
756         /// </summary>
757         /// <since_tizen> 6</since_tizen>
758         [EditorBrowsable(EditorBrowsableState.Never)]
759         public string AlphaMaskURL
760         {
761             get
762             {
763                 string ret = "";
764                 PropertyMap imageMap = new PropertyMap();
765                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
766                 image?.Get(imageMap);
767                 PropertyValue maskUrl = imageMap?.Find(ImageVisualProperty.AlphaMaskURL);
768                 maskUrl?.Get(out ret);
769                 _alphaMaskUrl = ret;
770
771                 imageMap?.Dispose();
772                 image?.Dispose();
773                 maskUrl?.Dispose();
774
775                 return ret;
776             }
777             set
778             {
779                 if (value == null)
780                 {
781                     value = "";
782                 }
783
784                 _alphaMaskUrl = value;
785
786                 PropertyValue setValue = new PropertyValue(value);
787                 UpdateImage(ImageVisualProperty.AlphaMaskURL, setValue);
788                 setValue?.Dispose();
789             }
790         }
791
792
793         /// <summary>
794         ///  Whether to crop image to mask or scale mask to fit image.
795         /// </summary>
796         /// <since_tizen> 6 </since_tizen>
797         public bool CropToMask
798         {
799             get
800             {
801                 bool ret = false;
802                 PropertyMap imageMap = new PropertyMap();
803                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
804                 image?.Get(imageMap);
805                 PropertyValue cropUrl = imageMap?.Find(ImageVisualProperty.CropToMask);
806                 cropUrl?.Get(out ret);
807
808                 imageMap?.Dispose();
809                 image?.Dispose();
810                 cropUrl?.Dispose();
811
812                 return ret;
813             }
814             set
815             {
816                 PropertyValue setValue = new PropertyValue(value);
817                 UpdateImage(ImageVisualProperty.CropToMask, setValue);
818                 setValue.Dispose();
819             }
820         }
821
822         internal VisualFittingModeType CovertFittingModetoVisualFittingMode(FittingModeType value)
823         {
824             switch (value)
825             {
826                 case FittingModeType.ShrinkToFit:
827                     return VisualFittingModeType.FitKeepAspectRatio;
828                 case FittingModeType.ScaleToFill:
829                     return VisualFittingModeType.OverFitKeepAspectRatio;
830                 case FittingModeType.Center:
831                     return VisualFittingModeType.Center;
832                 case FittingModeType.Fill:
833                     return VisualFittingModeType.Fill;
834                 case FittingModeType.FitHeight:
835                     return VisualFittingModeType.FitHeight;
836                 case FittingModeType.FitWidth:
837                     return VisualFittingModeType.FitHeight;
838                 default:
839                     return VisualFittingModeType.Fill;
840             }
841         }
842
843         internal FittingModeType ConvertVisualFittingModetoFittingMode(VisualFittingModeType value)
844         {
845             switch (value)
846             {
847                 case VisualFittingModeType.FitKeepAspectRatio:
848                     return FittingModeType.ShrinkToFit;
849                 case VisualFittingModeType.OverFitKeepAspectRatio:
850                     return FittingModeType.ScaleToFill;
851                 case VisualFittingModeType.Center:
852                     return FittingModeType.Center;
853                 case VisualFittingModeType.Fill:
854                     return FittingModeType.Fill;
855                 case VisualFittingModeType.FitHeight:
856                     return FittingModeType.FitHeight;
857                 case VisualFittingModeType.FitWidth:
858                     return FittingModeType.FitWidth;
859                 default:
860                     return FittingModeType.ShrinkToFit;
861             }
862         }
863
864         /// <summary>
865         /// Gets or sets fitting options used when resizing images to fit.<br />
866         /// If not supplied, the default is FittingModeType.Fill.<br />
867         /// For normal quad images only.<br />
868         /// Optional.
869         /// </summary>
870         /// <since_tizen> 6 </since_tizen>
871         [EditorBrowsable(EditorBrowsableState.Never)]
872         public FittingModeType FittingMode
873         {
874             get
875             {
876                 int ret = (int)_fittingMode;
877                 PropertyMap imageMap = new PropertyMap();
878                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
879                 image?.Get(imageMap);
880                 PropertyValue fittingMode = imageMap?.Find(Visual.Property.VisualFittingMode);
881                 fittingMode?.Get(out ret);
882                 _fittingMode = (VisualFittingModeType)ret;
883
884                 imageMap?.Dispose();
885                 image?.Dispose();
886                 fittingMode?.Dispose();
887
888                 return ConvertVisualFittingModetoFittingMode((VisualFittingModeType)ret);
889             }
890             set
891             {
892                 VisualFittingModeType ret = CovertFittingModetoVisualFittingMode(value);
893                 PropertyValue setValue = new PropertyValue((int)ret);
894                 if(_fittingMode != ret)
895                 {
896                     _fittingMode = ret;
897                     UpdateImage(Visual.Property.VisualFittingMode, setValue);
898                 }
899                 setValue?.Dispose();
900             }
901         }
902
903
904
905         /// <summary>
906         /// Gets or sets the desired image width.<br />
907         /// If not specified, the actual image width is used.<br />
908         /// For normal quad images only.<br />
909         /// Optional.
910         /// </summary>
911         /// <since_tizen> 6 </since_tizen>
912         [EditorBrowsable(EditorBrowsableState.Never)]
913         public int DesiredWidth
914         {
915             get
916             {
917                 PropertyMap imageMap = new PropertyMap();
918                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
919                 image?.Get(imageMap);
920                 PropertyValue desireWidth = imageMap?.Find(ImageVisualProperty.DesiredWidth);
921                 desireWidth?.Get(out _desired_width);
922
923                 imageMap?.Dispose();
924                 image?.Dispose();
925                 desireWidth?.Dispose();
926
927                 return _desired_width;
928             }
929             set
930             {
931                 if (_desired_width != value)
932                 {
933                     _desired_width = value;
934                     UpdateImage(0, null);
935                 }
936             }
937         }
938
939         /// <summary>
940         /// Gets or sets the desired image height.<br />
941         /// If not specified, the actual image height is used.<br />
942         /// For normal quad images only.<br />
943         /// Optional.
944         /// </summary>
945         /// <since_tizen> 6 </since_tizen>
946         [EditorBrowsable(EditorBrowsableState.Never)]
947         public int DesiredHeight
948         {
949             get
950             {
951                 PropertyMap imageMap = new PropertyMap();
952                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
953                 image?.Get(imageMap);
954                 PropertyValue desireheight = imageMap?.Find(ImageVisualProperty.DesiredHeight);
955                 desireheight?.Get(out _desired_height);
956
957                 imageMap?.Dispose();
958                 image?.Dispose();
959                 desireheight?.Dispose();
960
961                 return _desired_height;
962             }
963             set
964             {
965                 if (_desired_height != value)
966                 {
967                     _desired_height = value;
968                     UpdateImage(0, null);
969                 }
970             }
971         }
972
973         /// <summary>
974         /// Gets or sets ReleasePolicy for image.<br />
975         /// If not supplied, the default is ReleasePolicyType.Detached.<br />
976         /// </summary>
977         [EditorBrowsable(EditorBrowsableState.Never)]
978         public ReleasePolicyType ReleasePolicy
979         {
980             get
981             {
982                 int ret = (int)ReleasePolicyType.Detached;
983                 PropertyMap imageMap = new PropertyMap();
984                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
985                 image?.Get(imageMap);
986                 PropertyValue releasePoli = imageMap?.Find(ImageVisualProperty.ReleasePolicy);
987                 releasePoli?.Get(out ret);
988
989                 imageMap?.Dispose();
990                 image?.Dispose();
991                 releasePoli?.Dispose();
992
993                 return (ReleasePolicyType)ret;
994             }
995             set
996             {
997                 PropertyValue setValue = new PropertyValue((int)value);
998                 UpdateImage(ImageVisualProperty.ReleasePolicy, setValue);
999                 setValue?.Dispose();
1000             }
1001         }
1002
1003         /// <summary>
1004         /// Gets or sets the wrap mode for the u coordinate.<br />
1005         /// It decides how the texture should be sampled when the u coordinate exceeds the range of 0.0 to 1.0.<br />
1006         /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
1007         /// For normal quad images only.<br />
1008         /// Optional.
1009         /// </summary>
1010         /// <since_tizen> 6 </since_tizen>
1011         [EditorBrowsable(EditorBrowsableState.Never)]
1012         public WrapModeType WrapModeU
1013         {
1014             get
1015             {
1016                 int ret = (int)WrapModeType.Default;
1017                 PropertyMap imageMap = new PropertyMap();
1018                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1019                 image?.Get(imageMap);
1020                 PropertyValue warpModeU = imageMap?.Find(ImageVisualProperty.WrapModeU);
1021                 warpModeU?.Get(out ret);
1022
1023                 imageMap?.Dispose();
1024                 image?.Dispose();
1025                 warpModeU?.Dispose();
1026
1027                 return (WrapModeType)ret;
1028             }
1029             set
1030             {
1031                 PropertyValue setValue = new PropertyValue((int)value);
1032                 UpdateImage(ImageVisualProperty.WrapModeU, setValue);
1033                 setValue?.Dispose();
1034             }
1035         }
1036
1037         /// <summary>
1038         /// Gets or sets the wrap mode for the v coordinate.<br />
1039         /// It decides how the texture should be sampled when the v coordinate exceeds the range of 0.0 to 1.0.<br />
1040         /// The first two elements indicate the top-left position of the area, and the last two elements are the areas of the width and the height respectively.<br />
1041         /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
1042         /// For normal quad images only.
1043         /// Optional.
1044         /// </summary>
1045         /// <since_tizen> 6 </since_tizen>
1046         [EditorBrowsable(EditorBrowsableState.Never)]
1047         public WrapModeType WrapModeV
1048         {
1049             get
1050             {
1051                 int ret = (int)WrapModeType.Default;
1052                 PropertyMap imageMap = new PropertyMap();
1053                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1054                 image?.Get(imageMap);
1055                 PropertyValue wrapModeV = imageMap?.Find(ImageVisualProperty.WrapModeV);
1056                 wrapModeV?.Get(out ret);
1057
1058                 imageMap?.Dispose();
1059                 image?.Dispose();
1060                 wrapModeV?.Dispose();
1061
1062                 return (WrapModeType)ret;
1063             }
1064             set
1065             {
1066                 PropertyValue setValue = new PropertyValue((int)value);
1067                 UpdateImage(ImageVisualProperty.WrapModeV, setValue);
1068                 setValue?.Dispose();
1069             }
1070         }
1071
1072         internal Selector<string> ResourceUrlSelector
1073         {
1074             get => GetSelector<string>(resourceUrlSelector, ImageView.ResourceUrlProperty);
1075             set
1076             {
1077                 resourceUrlSelector?.Reset(this);
1078                 if (value == null) return;
1079
1080                 if (value.HasAll()) SetResourceUrl(value.All);
1081                 else resourceUrlSelector = new TriggerableSelector<string>(this, value, SetResourceUrl, true);
1082             }
1083         }
1084
1085         /// <summary>
1086         /// Get attributes, it is abstract function and must be override.
1087         /// </summary>
1088         [EditorBrowsable(EditorBrowsableState.Never)]
1089         protected override ViewStyle CreateViewStyle()
1090         {
1091             return new ImageViewStyle();
1092         }
1093
1094         internal void SetImage(string url, Uint16Pair size)
1095         {
1096             if (url.Contains(".json"))
1097             {
1098                 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
1099                 return;
1100             }
1101
1102             Interop.ImageView.SetImage(SwigCPtr, url, Uint16Pair.getCPtr(size));
1103             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1104
1105             ResourceUrl = url;
1106         }
1107
1108         internal ViewResourceReadySignal ResourceReadySignal(View view)
1109         {
1110             ViewResourceReadySignal ret = new ViewResourceReadySignal(Interop.View.ResourceReadySignal(View.getCPtr(view)), false);
1111             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1112             return ret;
1113         }
1114
1115         internal override void ApplyCornerRadius()
1116         {
1117             base.ApplyCornerRadius();
1118
1119             UpdateImage(0, null);
1120         }
1121
1122         internal override void ApplyBorderline()
1123         {
1124             base.ApplyBorderline();
1125
1126             // Apply borderline to IMAGE.
1127             if (backgroundExtraData != null)
1128             {
1129                 var borderlineColor = backgroundExtraData.BorderlineColor == null ? new PropertyValue(Color.Black) : new PropertyValue(backgroundExtraData.BorderlineColor);
1130
1131                 // Apply to the image visual
1132                 PropertyMap imageMap = new PropertyMap();
1133                 PropertyValue imageValue = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1134                 if (imageValue.Get(imageMap) && !imageMap.Empty())
1135                 {
1136                     imageMap[Visual.Property.BorderlineWidth] = new PropertyValue(backgroundExtraData.BorderlineWidth);
1137                     imageMap[Visual.Property.BorderlineColor] = borderlineColor;
1138                     imageMap[Visual.Property.BorderlineOffset] = new PropertyValue(backgroundExtraData.BorderlineOffset);
1139                     var temp = new PropertyValue(imageMap);
1140                     Tizen.NUI.Object.SetProperty(SwigCPtr, ImageView.Property.IMAGE, temp);
1141                     temp.Dispose();
1142                 }
1143                 imageMap.Dispose();
1144                 imageValue.Dispose();
1145                 borderlineColor.Dispose();
1146             }
1147
1148             UpdateImage(0, null);
1149         }
1150
1151         internal ResourceLoadingStatusType GetResourceStatus()
1152         {
1153             return (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.IMAGE);
1154         }
1155
1156         /// <summary>
1157         /// you can override it to clean-up your own resources.
1158         /// </summary>
1159         /// <param name="type">DisposeTypes</param>
1160         /// <since_tizen> 3 </since_tizen>
1161         protected override void Dispose(DisposeTypes type)
1162         {
1163             if (disposed)
1164             {
1165                 return;
1166             }
1167
1168             if (type == DisposeTypes.Explicit)
1169             {
1170                 //Called by User
1171                 //Release your own managed resources here.
1172                 //You should release all of your own disposable objects here.
1173                 _border?.Dispose();
1174                 _border = null;
1175                 borderSelector?.Reset(this);
1176                 resourceUrlSelector?.Reset(this);
1177             }
1178
1179             base.Dispose(type);
1180         }
1181
1182         /// This will not be public opened.
1183         [EditorBrowsable(EditorBrowsableState.Never)]
1184         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1185         {
1186             Interop.ImageView.DeleteImageView(swigCPtr);
1187         }
1188
1189         // Callback for View ResourceReady signal
1190         private void OnResourceReady(IntPtr data)
1191         {
1192             ResourceReadyEventArgs e = new ResourceReadyEventArgs();
1193             if (data != null)
1194             {
1195                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1196             }
1197
1198             if (_resourceReadyEventHandler != null)
1199             {
1200                 _resourceReadyEventHandler(this, e);
1201             }
1202         }
1203
1204         private void SetResourceUrl(string value)
1205         {
1206             value = (value == null ? "" : value);
1207             if (value.StartsWith("*Resource*"))
1208             {
1209                 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
1210                 value = value.Replace("*Resource*", resource);
1211             }
1212             _resourceUrl = value;
1213             UpdateImage(ImageVisualProperty.URL, new PropertyValue(value));
1214         }
1215
1216         private void SetBorder(Rectangle value)
1217         {
1218             if (value == null)
1219             {
1220                 return;
1221             }
1222             _border = new Rectangle(value);
1223             UpdateImage(NpatchImageVisualProperty.Border, new PropertyValue(_border));
1224         }
1225
1226         private void UpdateImageMap(PropertyMap fromMap)
1227         {
1228             PropertyMap imageMap = new PropertyMap();
1229
1230             PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1231             image?.Get(imageMap);
1232             imageMap?.Merge(fromMap);
1233             PropertyValue setValue = new PropertyValue(imageMap);
1234             SetProperty(ImageView.Property.IMAGE, setValue);
1235
1236             imageMap?.Dispose();
1237             image?.Dispose();
1238             setValue?.Dispose();
1239         }
1240
1241         private void UpdateImage(int key, PropertyValue value)
1242         {
1243             PropertyMap imageMap = new PropertyMap();
1244
1245             if (_alphaMaskUrl != null)
1246             {
1247                 PropertyValue alphaMaskUrl = new PropertyValue(_alphaMaskUrl);
1248                 imageMap?.Insert(ImageVisualProperty.AlphaMaskURL, alphaMaskUrl);
1249                 alphaMaskUrl?.Dispose();
1250             }
1251
1252             if (string.IsNullOrEmpty(_resourceUrl))
1253             {
1254                 PropertyValue resourceUrl = new PropertyValue(_resourceUrl);
1255                 imageMap?.Insert(ImageVisualProperty.URL, resourceUrl);
1256                 PropertyValue setValue = new PropertyValue(imageMap);
1257                 SetProperty(ImageView.Property.IMAGE, setValue);
1258                 resourceUrl?.Dispose();
1259                 setValue?.Dispose();
1260                 return;
1261             }
1262
1263             if (_border == null)
1264             {
1265                 PropertyValue image = new PropertyValue((int)Visual.Type.Image);
1266                 imageMap?.Insert(Visual.Property.Type, image);
1267                 image?.Dispose();
1268             }
1269             else
1270             {
1271                 PropertyValue nPatch = new PropertyValue((int)Visual.Type.NPatch);
1272                 imageMap?.Insert(Visual.Property.Type, nPatch);
1273                 nPatch?.Dispose();
1274                 PropertyValue border = new PropertyValue(_border);
1275                 imageMap?.Insert(NpatchImageVisualProperty.Border, border);
1276                 border?.Dispose();
1277             }
1278
1279             if(key != Visual.Property.VisualFittingMode && _fittingMode != VisualFittingModeType.Fill)
1280             {
1281                 PropertyValue fittingMode = new PropertyValue((int)_fittingMode);
1282                 imageMap?.Insert(Visual.Property.VisualFittingMode, fittingMode);
1283                 fittingMode?.Dispose();
1284             }
1285
1286             PropertyValue synchronosLoading = new PropertyValue(_synchronosLoading);
1287             imageMap?.Insert(NpatchImageVisualProperty.SynchronousLoading, synchronosLoading);
1288             synchronosLoading?.Dispose();
1289
1290             if (backgroundExtraData != null && backgroundExtraData.CornerRadius != null)
1291             {
1292                 using (var cornerRadius = new PropertyValue(backgroundExtraData.CornerRadius))
1293                 using (var cornerRadiusPolicy = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy))
1294                 {
1295                     imageMap.Insert(Visual.Property.CornerRadius, cornerRadius);
1296                     imageMap.Insert(Visual.Property.CornerRadiusPolicy, new PropertyValue((int)(backgroundExtraData.CornerRadiusPolicy)));
1297                 }
1298             }
1299
1300             if (backgroundExtraData != null && backgroundExtraData.BorderlineWidth > 0.0f)
1301             {
1302                 using (var borderlineWidth = new PropertyValue(backgroundExtraData.BorderlineWidth))
1303                 using (var borderlineColor = new PropertyValue(backgroundExtraData.BorderlineColor))
1304                 using (var borderlineOffset = new PropertyValue(backgroundExtraData.BorderlineOffset))
1305                 {
1306                     imageMap.Insert(Visual.Property.BorderlineWidth, borderlineWidth);
1307                     imageMap.Insert(Visual.Property.BorderlineColor, borderlineColor);
1308                     imageMap.Insert(Visual.Property.BorderlineOffset, borderlineOffset);
1309                 }
1310             }
1311
1312             if (value != null)
1313             {
1314                 imageMap?.Insert(key, value);
1315             }
1316
1317             // Do Fitting Buffer when desired dimension is set
1318             if (_desired_width != -1 && _desired_height != -1)
1319             {
1320                 if (_resourceUrl != null)
1321                 {
1322                     Size2D imageSize = ImageLoading.GetOriginalImageSize(_resourceUrl, true);
1323                     if( imageSize.Height > 0 && imageSize.Width > 0 && _desired_width > 0  && _desired_height > 0 )
1324                     {
1325                         int adjustedDesiredWidth, adjustedDesiredHeight;
1326                         float aspectOfDesiredSize = (float)_desired_height / (float)_desired_width;
1327                         float aspectOfImageSize = (float)imageSize.Height / (float)imageSize.Width;
1328                         if (aspectOfImageSize > aspectOfDesiredSize)
1329                         {
1330                             adjustedDesiredWidth = _desired_width;
1331                             adjustedDesiredHeight = imageSize.Height * _desired_width / imageSize.Width;
1332                         }
1333                         else
1334                         {
1335                             adjustedDesiredWidth = imageSize.Width * _desired_height / imageSize.Height;
1336                             adjustedDesiredHeight = _desired_height;
1337                         }
1338
1339                         PropertyValue returnWidth = new PropertyValue(adjustedDesiredWidth);
1340                         imageMap?.Insert(ImageVisualProperty.DesiredWidth, returnWidth);
1341                         returnWidth?.Dispose();
1342                         PropertyValue returnHeight = new PropertyValue(adjustedDesiredHeight);
1343                         imageMap?.Insert(ImageVisualProperty.DesiredHeight, returnHeight);
1344                         returnHeight?.Dispose();
1345                         PropertyValue scaleToFit = new PropertyValue((int)FittingModeType.ScaleToFill);
1346                         imageMap?.Insert(ImageVisualProperty.FittingMode, scaleToFit);
1347                         scaleToFit?.Dispose();
1348                     }
1349                     else
1350                     {
1351                         Tizen.Log.Fatal("NUI", "[ERROR] Can't use DesiredSize when ImageLoading is failed.");
1352                     }
1353                     imageSize?.Dispose();
1354                 }
1355             }
1356
1357             UpdateImageMap(imageMap);
1358
1359             imageMap?.Dispose();
1360             imageMap = null;
1361         }
1362
1363
1364         private void OnResourceLoaded(IntPtr view)
1365         {
1366             ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
1367             e.Status = (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.IMAGE);
1368
1369             if (_resourceLoadedEventHandler != null)
1370             {
1371                 _resourceLoadedEventHandler(this, e);
1372             }
1373         }
1374
1375         /// <summary>
1376         /// Event arguments of resource ready.
1377         /// </summary>
1378         /// <since_tizen> 3 </since_tizen>
1379         public class ResourceReadyEventArgs : EventArgs
1380         {
1381             private View _view;
1382
1383             /// <summary>
1384             /// The view whose resource is ready.
1385             /// </summary>
1386             /// <since_tizen> 3 </since_tizen>
1387             public View View
1388             {
1389                 get
1390                 {
1391                     return _view;
1392                 }
1393                 set
1394                 {
1395                     _view = value;
1396                 }
1397             }
1398         }
1399
1400         internal class ResourceLoadedEventArgs : EventArgs
1401         {
1402             private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1403             public ResourceLoadingStatusType Status
1404             {
1405                 get
1406                 {
1407                     return status;
1408                 }
1409                 set
1410                 {
1411                     status = value;
1412                 }
1413             }
1414         }
1415
1416         internal new class Property
1417         {
1418             internal static readonly int IMAGE = Interop.ImageView.ImageGet();
1419             internal static readonly int PreMultipliedAlpha = Interop.ImageView.PreMultipliedAlphaGet();
1420             internal static readonly int PixelArea = Interop.ImageView.PixelAreaGet();
1421             internal static readonly int ActionReload = Interop.ImageView.ImageVisualActionReloadGet();
1422             internal static readonly int ActionPlay = Interop.ImageView.ImageVisualActionPlayGet();
1423             internal static readonly int ActionPause = Interop.ImageView.ImageVisualActionPauseGet();
1424             internal static readonly int ActionStop = Interop.ImageView.ImageVisualActionStopGet();
1425         }
1426
1427         private enum ImageType
1428         {
1429             /// <summary>
1430             /// For Normal Image.
1431             /// </summary>
1432             Normal = 0,
1433
1434             /// <summary>
1435             /// For normal image, with synchronous loading and orientation correction property
1436             /// </summary>
1437             Specific = 1,
1438
1439             /// <summary>
1440             /// For nine-patch image
1441             /// </summary>
1442             Npatch = 2,
1443         }
1444
1445         private void OnBorderChanged(int x, int y, int width, int height)
1446         {
1447             Border = new Rectangle(x, y, width, height);
1448         }
1449         private void OnPixelAreaChanged(float x, float y, float z, float w)
1450         {
1451             PixelArea = new RelativeVector4(x, y, z, w);
1452         }
1453     }
1454 }