[NUI] Fix FittingMode bug (#1319)
[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             string url = (string)newValue;
40             url = (url == null ? "" : url);
41             if (imageView.IsCreateByXaml && url.Contains("*Resource*"))
42             {
43                 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
44                 url = url.Replace("*Resource*", resource);
45             }
46             imageView._resourceUrl = url;
47             imageView.UpdateImage(ImageVisualProperty.URL, new PropertyValue(url));
48         },
49         defaultValueCreator: (bindable) =>
50         {
51             var imageView = (ImageView)bindable;
52             string ret = "";
53                         
54             PropertyMap imageMap = new PropertyMap();
55             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
56             imageMap.Find(ImageVisualProperty.URL)?.Get(out ret);
57             return ret;
58         });
59
60         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
61         [EditorBrowsable(EditorBrowsableState.Never)]
62         public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(ImageView.Image), typeof(PropertyMap), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
63         {
64             var imageView = (ImageView)bindable;
65             if (newValue != null)
66             {
67                 PropertyMap map = (PropertyMap)newValue;
68                 if (imageView.IsCreateByXaml)
69                 {
70                     string url = "", alphaMaskURL = "", auxiliaryImageURL = "";
71                     string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
72                     PropertyValue urlValue = map.Find(NDalic.IMAGE_VISUAL_URL);
73                     bool ret = false;
74                     if (urlValue != null) ret = urlValue.Get(out url);
75                     PropertyMap mmap = new PropertyMap();
76                     if (ret && url.Contains("*Resource*"))
77                     {
78                         url = url.Replace("*Resource*", resource);
79                         mmap.Insert(NDalic.IMAGE_VISUAL_URL, new PropertyValue(url));
80                     }
81
82                     ret = false;
83                     PropertyValue alphaMaskUrlValue = map.Find(NDalic.IMAGE_VISUAL_ALPHA_MASK_URL);
84                     if (alphaMaskUrlValue != null) ret = alphaMaskUrlValue.Get(out alphaMaskURL);
85                     if (ret && alphaMaskURL.Contains("*Resource*"))
86                     {
87                         alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource);
88                         mmap.Insert(NDalic.IMAGE_VISUAL_URL, new PropertyValue(alphaMaskURL));
89                     }
90
91                     ret = false;
92                     PropertyValue auxiliaryImageURLValue = map.Find(NDalic.IMAGE_VISUAL_AUXILIARY_IMAGE_URL);
93                     if (auxiliaryImageURLValue != null) ret = auxiliaryImageURLValue.Get(out auxiliaryImageURL);
94                     if (ret && auxiliaryImageURL.Contains("*Resource*"))
95                     {
96                         auxiliaryImageURL = auxiliaryImageURL.Replace("*Resource*", resource);
97                         mmap.Insert(NDalic.IMAGE_VISUAL_AUXILIARY_IMAGE_URL, new PropertyValue(auxiliaryImageURL));
98                     }
99
100                     map.Merge(mmap);
101                 }
102                 if (imageView._border == null)
103                 {
104                     Tizen.NUI.Object.SetProperty(imageView.swigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
105                 }
106             }
107         },
108         defaultValueCreator: (bindable) =>
109         {
110             var imageView = (ImageView)bindable;
111             if (imageView._border == null)
112             {
113                 PropertyMap temp = new PropertyMap();
114                 Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(temp);
115                 return temp;
116             }
117             else
118             {
119                 return null;
120             }
121         });
122
123         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
124         [EditorBrowsable(EditorBrowsableState.Never)]
125         public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create("PreMultipliedAlpha", typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
126         {
127             var imageView = (ImageView)bindable;
128             if (newValue != null)
129             {
130                 Tizen.NUI.Object.SetProperty(imageView.swigCPtr, ImageView.Property.PRE_MULTIPLIED_ALPHA, new Tizen.NUI.PropertyValue((bool)newValue));
131             }
132         },
133         defaultValueCreator: (bindable) =>
134         {
135             var imageView = (ImageView)bindable;
136             bool temp = false;
137             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.PRE_MULTIPLIED_ALPHA).Get(out temp);
138             return temp;
139         });
140
141         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
142         [EditorBrowsable(EditorBrowsableState.Never)]
143         public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create("PixelArea", typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
144         {
145             var imageView = (ImageView)bindable;
146             if (newValue != null)
147             {
148                 Tizen.NUI.Object.SetProperty(imageView.swigCPtr, ImageView.Property.PIXEL_AREA, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
149             }
150         },
151         defaultValueCreator: (bindable) =>
152         {
153             var imageView = (ImageView)bindable;
154             Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
155             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.PIXEL_AREA).Get(temp);
156             RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
157             return relativeTemp;
158         });
159
160         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
161         [EditorBrowsable(EditorBrowsableState.Never)]
162         public static readonly BindableProperty BorderProperty = BindableProperty.Create("Border", typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
163         {
164             if(newValue != null)
165             {
166                 var imageView = (ImageView)bindable;
167                 imageView._border = (Rectangle)newValue;
168                 imageView.UpdateImage(NpatchImageVisualProperty.Border, new PropertyValue(imageView._border));
169             }
170         },
171         defaultValueCreator: (bindable) =>
172         {
173             var imageView = (ImageView)bindable;
174             return imageView._border;
175         });
176
177         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
178         [EditorBrowsable(EditorBrowsableState.Never)]
179         public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create("BorderOnly", typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
180         {
181             var imageView = (ImageView)bindable;
182             if (newValue != null)
183             {
184                 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
185             }
186         },
187         defaultValueCreator: (bindable) =>
188         {
189             var imageView = (ImageView)bindable;
190             bool ret = false;
191             PropertyMap imageMap = new PropertyMap();
192             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
193             imageMap.Find(ImageVisualProperty.BorderOnly)?.Get(out ret);
194             return ret;
195         });
196
197         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
198         [EditorBrowsable(EditorBrowsableState.Never)]
199         public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create("SynchronosLoading", typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
200         {
201             var imageView = (ImageView)bindable;
202             if (newValue != null)
203             {
204                 imageView._synchronosLoading = (bool) newValue;
205                 imageView.UpdateImage(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
206             }
207         },
208         defaultValueCreator: (bindable) =>
209         {
210             var imageView = (ImageView)bindable;
211             return imageView._synchronosLoading;
212         });
213
214         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
215         [EditorBrowsable(EditorBrowsableState.Never)]
216         public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create("OrientationCorrection", typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
217         {
218             var imageView = (ImageView)bindable;
219             if (newValue != null)
220             {
221                 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
222             }
223         },
224         defaultValueCreator: (bindable) =>
225         {
226             var imageView = (ImageView)bindable;
227             
228             bool ret = false;
229             PropertyMap imageMap = new PropertyMap();
230             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
231             imageMap?.Find(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
232
233             return ret;
234         });
235
236         private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
237         private ResourceReadyEventCallbackType _resourceReadyEventCallback;
238         private EventHandler<ResourceLoadedEventArgs> _resourceLoadedEventHandler;
239         private _resourceLoadedCallbackType _resourceLoadedCallback;
240
241         private Rectangle _border;
242         private string _resourceUrl = "";
243         private bool _synchronosLoading = false;
244
245         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
246         [EditorBrowsable(EditorBrowsableState.Never)]
247         public ImageViewStyle Style => ViewStyle as ImageViewStyle;
248
249         /// <summary>
250         /// Creates an initialized ImageView.
251         /// </summary>
252         /// <since_tizen> 3 </since_tizen>
253         public ImageView() : this(Interop.ImageView.ImageView_New__SWIG_0(), true)
254         {
255             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256         }
257
258         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
259         [EditorBrowsable(EditorBrowsableState.Never)]
260         public ImageView(ViewStyle viewStyle) : this(Interop.ImageView.ImageView_New__SWIG_0(), true, viewStyle)
261         {
262         }
263
264         /// <summary>
265         /// Creates an initialized ImageView with setting the status of shown or hidden.
266         /// </summary>
267         /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
268         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
269         [EditorBrowsable(EditorBrowsableState.Never)]
270         public ImageView(bool shown) : this(Interop.ImageView.ImageView_New__SWIG_0(), true)
271         {
272             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273             SetVisible(shown);
274         }
275
276         /// <summary>
277         /// Creates an initialized ImageView from a URL to an image resource.<br />
278         /// If the string is empty, ImageView will not display anything.<br />
279         /// </summary>
280         /// <param name="url">The URL of the image resource to display.</param>
281         /// <since_tizen> 3 </since_tizen>
282         public ImageView(string url) : this(Interop.ImageView.ImageView_New__SWIG_2(url), true)
283         {
284             ResourceUrl = url;
285             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286
287         }
288
289         /// <summary>
290         /// Creates an initialized ImageView from a URL to an image resource with setting shown or hidden.
291         /// </summary>
292         /// <param name="url">The URL of the image resource to display.</param>
293         /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
294         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
295         [EditorBrowsable(EditorBrowsableState.Never)]
296         public ImageView(string url, bool shown) : this(Interop.ImageView.ImageView_New__SWIG_2(url), true)
297         {
298             ResourceUrl = url;
299             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300             SetVisible(shown);
301         }
302
303         internal ImageView(string url, Uint16Pair size, bool shown = true) : this(Interop.ImageView.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true)
304         {
305             ResourceUrl = url;
306             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307
308             if (!shown)
309             {
310                 SetVisible(false);
311             }
312         }
313
314         internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(Interop.ImageView.ImageView_SWIGUpcast(cPtr), cMemoryOwn, viewStyle)
315         {
316             if (!shown)
317             {
318                 SetVisible(false);
319             }
320         }
321
322         internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(Interop.ImageView.ImageView_SWIGUpcast(cPtr), cMemoryOwn)
323         {
324             if (!shown)
325             {
326                 SetVisible(false);
327             }
328         }
329
330         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
331         private delegate void ResourceReadyEventCallbackType(IntPtr data);
332         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
333         private delegate void _resourceLoadedCallbackType(IntPtr view);
334
335         /// <summary>
336         /// An event for ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
337         /// This signal is emitted after all resources required by a control are loaded and ready.<br />
338         /// Most resources are only loaded when the control is placed on the stage.<br />
339         /// </summary>
340         /// <since_tizen> 3 </since_tizen>
341         public event EventHandler<ResourceReadyEventArgs> ResourceReady
342         {
343             add
344             {
345                 if (_resourceReadyEventHandler == null)
346                 {
347                     _resourceReadyEventCallback = OnResourceReady;
348                     ResourceReadySignal(this).Connect(_resourceReadyEventCallback);
349                 }
350
351                 _resourceReadyEventHandler += value;
352             }
353
354             remove
355             {
356                 _resourceReadyEventHandler -= value;
357
358                 if (_resourceReadyEventHandler == null && ResourceReadySignal(this).Empty() == false)
359                 {
360                     ResourceReadySignal(this).Disconnect(_resourceReadyEventCallback);
361                 }
362             }
363         }
364
365         internal event EventHandler<ResourceLoadedEventArgs> ResourceLoaded
366         {
367             add
368             {
369                 if (_resourceLoadedEventHandler == null)
370                 {
371                     _resourceLoadedCallback = OnResourceLoaded;
372                     this.ResourceReadySignal(this).Connect(_resourceLoadedCallback);
373                 }
374
375                 _resourceLoadedEventHandler += value;
376             }
377             remove
378             {
379                 _resourceLoadedEventHandler -= value;
380
381                 if (_resourceLoadedEventHandler == null && this.ResourceReadySignal(this).Empty() == false)
382                 {
383                     this.ResourceReadySignal(this).Disconnect(_resourceLoadedCallback);
384                 }
385             }
386         }
387
388         /// <summary>
389         /// Enumeration for LoadingStatus of image.
390         /// </summary>
391         /// <since_tizen> 5 </since_tizen>
392         public enum LoadingStatusType
393         {
394             /// <summary>
395             /// Loading preparing status.
396             /// </summary>
397             /// <since_tizen> 5 </since_tizen>
398             Preparing,
399             /// <summary>
400             /// Loading ready status.
401             /// </summary>
402             /// <since_tizen> 5 </since_tizen>
403             Ready,
404             /// <summary>
405             /// Loading failed status.
406             /// </summary>
407             /// <since_tizen> 5 </since_tizen>
408             Failed
409         }
410
411         /// <summary>
412         /// ImageView ResourceUrl, type string.
413         /// This is one of mandatory property. Even if not set or null set, it sets empty string ("") internally.
414         /// When it is set as null, it gives empty string ("") to be read.
415         /// </summary>
416         /// <since_tizen> 3 </since_tizen>
417         public string ResourceUrl
418         {
419             get
420             {
421                 return (string)GetValue(ResourceUrlProperty);
422             }
423             set
424             {
425                 SetValue(ResourceUrlProperty, value);
426                 NotifyPropertyChanged();       
427             }
428         }
429
430         /// <summary>
431         /// This will be deprecated, please use Image instead. <br />
432         /// ImageView ImageMap, type PropertyMap: string if it is a URL, map otherwise.
433         /// </summary>
434         /// <since_tizen> 3 </since_tizen>
435         [Obsolete("Please do not use! This will be deprecated! Please use Image property instead!")]
436         [EditorBrowsable(EditorBrowsableState.Never)]
437         public PropertyMap ImageMap
438         {
439             get
440             {
441                 if (_border == null)
442                 {
443                     PropertyMap temp = new PropertyMap();
444                     GetProperty(ImageView.Property.IMAGE).Get(temp);
445                     return temp;
446                 }
447                 else
448                 {
449                     return null;
450                 }
451             }
452             set
453             {
454                 if (_border == null)
455                 {
456                     SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
457                     NotifyPropertyChanged();
458                 }
459             }
460         }
461
462         /// <summary>
463         /// ImageView Image, type PropertyMap
464         /// </summary>
465         /// <since_tizen> 4 </since_tizen>
466         public PropertyMap Image
467         {
468             get
469             {
470                 if (_border == null)
471                 {
472                     return (PropertyMap)GetValue(ImageProperty);
473                 }
474                 else
475                 {
476                     return null;
477                 }
478             }
479             set
480             {
481                 if (_border == null)
482                 {
483                     SetValue(ImageProperty, value);
484                     NotifyPropertyChanged();
485                 }
486             }
487         }
488
489         /// <summary>
490         /// ImageView PreMultipliedAlpha, type Boolean.<br />
491         /// Image must be initialized.<br />
492         /// </summary>
493         /// <since_tizen> 3 </since_tizen>
494         public bool PreMultipliedAlpha
495         {
496             get
497             {
498                 return (bool)GetValue(PreMultipliedAlphaProperty);
499             }
500             set
501             {
502                 SetValue(PreMultipliedAlphaProperty, value);
503                 NotifyPropertyChanged();
504             }
505         }
506
507         /// <summary>
508         /// ImageView PixelArea, type Vector4 (Animatable property).<br />
509         /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br />
510         /// </summary>
511         /// <remarks>
512         /// The property cascade chaining set is possible. For example, this (imageView.PixelArea.X = 0.1f;) is possible.
513         /// </remarks>
514         /// <since_tizen> 3 </since_tizen>
515         public RelativeVector4 PixelArea
516         {
517             get
518             {
519                 RelativeVector4 temp = (RelativeVector4)GetValue(PixelAreaProperty);
520                 return new RelativeVector4(OnPixelAreaChanged, temp.X, temp.Y, temp.Z, temp.W);
521             }
522             set
523             {
524                 SetValue(PixelAreaProperty, value);
525                 NotifyPropertyChanged();
526             }
527         }
528
529         /// <summary>
530         /// The border of the image in the order: left, right, bottom, top.<br />
531         /// If set, ImageMap will be ignored.<br />
532         /// For N-Patch images only.<br />
533         /// Optional.
534         /// </summary>
535         /// <remarks>
536         /// The property cascade chaining set is possible. For example, this (imageView.Border.X = 1;) is possible.
537         /// </remarks>
538         /// <since_tizen> 3 </since_tizen>
539         public Rectangle Border
540         {
541             get
542             {
543                 Rectangle temp = (Rectangle)GetValue(BorderProperty);
544                 if (null == temp)
545                 {
546                     return null;
547                 }
548                 else
549                 {
550                     return new Rectangle(OnBorderChanged, temp.X, temp.Y, temp.Width, temp.Height);
551                 }
552             }
553             set
554             {
555                 SetValue(BorderProperty, value);
556                 NotifyPropertyChanged();
557             }
558         }
559
560         /// <summary>
561         /// Gets or sets whether to draw the borders only (if true).<br />
562         /// If not specified, the default is false.<br />
563         /// For N-Patch images only.<br />
564         /// Optional.
565         /// </summary>
566         /// <since_tizen> 3 </since_tizen>
567         public bool BorderOnly
568         {
569             get
570             {
571                 return (bool)GetValue(BorderOnlyProperty);
572             }
573             set
574             {
575                 SetValue(BorderOnlyProperty, value);
576                 NotifyPropertyChanged();
577             }
578         }
579
580         /// <summary>
581         /// Gets or sets whether to synchronos loading the resourceurl of image.<br />
582         /// </summary>
583         /// <since_tizen> 3 </since_tizen>
584         public bool SynchronosLoading
585         {
586             get
587             {
588                 return (bool)GetValue(SynchronosLoadingProperty);
589             }
590             set
591             {
592                 SetValue(SynchronosLoadingProperty, value);
593                 NotifyPropertyChanged();
594             }
595         }
596
597         /// <summary>
598         /// Gets or sets whether to automatically correct the orientation of an image.<br />
599         /// </summary>
600         /// <since_tizen> 5 </since_tizen>
601         public bool OrientationCorrection
602         {
603             get
604             {
605                 return (bool)GetValue(OrientationCorrectionProperty);
606             }
607             set
608             {
609                 SetValue(OrientationCorrectionProperty, value);
610                 NotifyPropertyChanged();
611             }
612         }
613
614         /// <summary>
615         /// Gets the loading state of the visual resource.
616         /// </summary>
617         /// <since_tizen> 5 </since_tizen>
618         public ImageView.LoadingStatusType LoadingStatus
619         {
620             get
621             {
622                 return (ImageView.LoadingStatusType)Interop.View.View_GetVisualResourceStatus(swigCPtr, (int)Property.IMAGE);
623             }
624         }
625
626         /// <summary>
627         /// Downcasts a handle to imageView handle.
628         /// </summary>
629         /// Please do not use! this will be deprecated!
630         /// Instead please use as keyword.
631         /// <since_tizen> 3 </since_tizen>
632         [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
633         "Like: " +
634         "BaseHandle handle = new ImageView(imagePath); " +
635         "ImageView image = handle as ImageView")]
636         [EditorBrowsable(EditorBrowsableState.Never)]
637         public static ImageView DownCast(BaseHandle handle)
638         {
639             ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
640             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
641             return ret;
642         }
643
644         /// <summary>
645         /// Sets this ImageView from the given URL.<br />
646         /// If the URL is empty, ImageView will not display anything.<br />
647         /// </summary>
648         /// <param name="url">The URL to the image resource to display.</param>
649         /// <since_tizen> 3 </since_tizen>
650         public void SetImage(string url)
651         {
652             if(url.Contains(".json"))
653             {
654                 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
655                 return;
656             }
657
658             Interop.ImageView.ImageView_SetImage__SWIG_1(swigCPtr, url);
659             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
660
661             ResourceUrl = url;
662         }
663
664         /// <summary>
665         /// Queries if all resources required by a control are loaded and ready.<br />
666         /// Most resources are only loaded when the control is placed on the stage.<br />
667         /// True if the resources are loaded and ready, false otherwise.<br />
668         /// </summary>
669         /// <since_tizen> 3 </since_tizen>
670         public new bool IsResourceReady()
671         {
672             bool ret = Interop.View.IsResourceReady(swigCPtr);
673             if (NDalicPINVOKE.SWIGPendingException.Pending)
674                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
675             return ret;
676         }
677
678         /// <summary>
679         /// Forcefully reloads the image. All the visuals using this image will reload to the latest image.
680         /// </summary>
681         /// <since_tizen> 5 </since_tizen>
682         public void Reload()
683         {
684             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_RELOAD, new PropertyValue(0));
685         }
686
687         /// <summary>
688         /// Plays the animated GIF. This is also the default playback mode.
689         /// </summary>
690         /// <since_tizen> 5 </since_tizen>
691         public void Play()
692         {
693             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_PLAY, new PropertyValue(0));
694         }
695
696         /// <summary>
697         /// Pauses the animated GIF.
698         /// </summary>
699         /// <since_tizen> 5 </since_tizen>
700         public void Pause()
701         {
702             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_PAUSE, new PropertyValue(0));
703         }
704
705         /// <summary>
706         /// Stops the animated GIF.
707         /// </summary>
708         /// <since_tizen> 5 </since_tizen>
709         public void Stop()
710         {
711             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_STOP, new PropertyValue(0));
712         }
713
714         /// <summary>
715         /// Gets or sets the URL of the alpha mask.<br />
716         /// Optional.
717         /// </summary>
718         /// <since_tizen> 6</since_tizen>
719         [EditorBrowsable(EditorBrowsableState.Never)]
720         public string AlphaMaskURL
721         {
722             get
723             {
724                 string ret = "";
725                 PropertyMap imageMap = new PropertyMap();
726                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
727                 imageMap?.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out ret);
728
729                 return ret;
730             }
731             set
732             {
733                 if (value == null)
734                 {
735                     value = "";
736                 }
737
738                 UpdateImage(ImageVisualProperty.AlphaMaskURL, new PropertyValue(value));
739             }
740         }
741
742
743         /// <summary>
744         ///  Whether to crop image to mask or scale mask to fit image.
745         /// </summary>
746         /// <since_tizen> 6 </since_tizen>
747         public bool CropToMask
748         {
749             get
750             {
751                 bool ret = false;
752                 PropertyMap imageMap = new PropertyMap();
753                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
754                 imageMap?.Find(ImageVisualProperty.CropToMask)?.Get(out ret);
755
756                 return ret;
757             }
758             set
759             {
760                 UpdateImage(ImageVisualProperty.CropToMask, new PropertyValue(value));
761             }
762         }
763
764
765         /// <summary>
766         /// Gets or sets fitting options used when resizing images to fit the desired dimensions.<br />
767         /// If not supplied, the default is FittingModeType.ShrinkToFit.<br />
768         /// For normal quad images only.<br />
769         /// Optional.
770         /// </summary>
771         /// <since_tizen> 6 </since_tizen>
772         [EditorBrowsable(EditorBrowsableState.Never)]
773         public FittingModeType FittingMode
774         {
775             get
776             {
777                 int ret = (int)FittingModeType.ShrinkToFit;
778                 PropertyMap imageMap = new PropertyMap();
779                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
780                 imageMap?.Find(ImageVisualProperty.FittingMode)?.Get(out ret);
781
782                 return (FittingModeType)ret;
783             }
784             set
785             {
786                 UpdateImage(ImageVisualProperty.FittingMode, new PropertyValue((int)value));
787             }
788         }
789
790
791
792         /// <summary>
793         /// Gets or sets the desired image width.<br />
794         /// If not specified, the actual image width is used.<br />
795         /// For normal quad images only.<br />
796         /// Optional.
797         /// </summary>
798         /// <since_tizen> 6 </since_tizen>
799         [EditorBrowsable(EditorBrowsableState.Never)]
800         public int DesiredWidth
801         {
802             get
803             {
804                 int ret = -1;
805                 PropertyMap imageMap = new PropertyMap();
806                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
807                 imageMap?.Find(ImageVisualProperty.DesiredWidth)?.Get(out ret);
808
809                 return ret;
810             }
811             set
812             {
813                 UpdateImage(ImageVisualProperty.DesiredWidth, new PropertyValue(value));
814             }
815         }
816
817         /// <summary>
818         /// Gets or sets the desired image height.<br />
819         /// If not specified, the actual image height is used.<br />
820         /// For normal quad images only.<br />
821         /// Optional.
822         /// </summary>
823         /// <since_tizen> 6 </since_tizen>
824         [EditorBrowsable(EditorBrowsableState.Never)]
825         public int DesiredHeight
826         {
827             get
828             {
829                 int ret = -1;
830                 PropertyMap imageMap = new PropertyMap();
831                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
832                 imageMap?.Find(ImageVisualProperty.DesiredHeight)?.Get(out ret);
833
834                 return ret;
835             }
836             set
837             {
838                 UpdateImage(ImageVisualProperty.DesiredHeight, new PropertyValue(value));
839             }
840         }
841
842
843         /// <summary>
844         /// Gets or sets the wrap mode for the u coordinate.<br />
845         /// It decides how the texture should be sampled when the u coordinate exceeds the range of 0.0 to 1.0.<br />
846         /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
847         /// For normal quad images only.<br />
848         /// Optional.
849         /// </summary>
850         /// <since_tizen> 6 </since_tizen>
851         [EditorBrowsable(EditorBrowsableState.Never)]
852         public WrapModeType WrapModeU
853         {
854             get
855             {
856                 int ret = (int)WrapModeType.Default;
857                 PropertyMap imageMap = new PropertyMap();
858                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
859                 imageMap?.Find(ImageVisualProperty.WrapModeU)?.Get(out ret);
860
861                 return (WrapModeType)ret;
862             }
863             set
864             {
865                 UpdateImage(ImageVisualProperty.WrapModeU, new PropertyValue((int)value));
866             }
867         }
868
869         /// <summary>
870         /// Gets or sets the wrap mode for the v coordinate.<br />
871         /// It decides how the texture should be sampled when the v coordinate exceeds the range of 0.0 to 1.0.<br />
872         /// 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 />
873         /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
874         /// For normal quad images only.
875         /// Optional.
876         /// </summary>
877         /// <since_tizen> 6 </since_tizen>
878         [EditorBrowsable(EditorBrowsableState.Never)]
879         public WrapModeType WrapModeV
880         {
881             get
882             {
883                 int ret = (int)WrapModeType.Default;
884                 PropertyMap imageMap = new PropertyMap();
885                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
886                 imageMap?.Find(ImageVisualProperty.WrapModeV)?.Get(out ret);
887
888                 return (WrapModeType)ret;
889             }
890             set
891             {
892                 UpdateImage(ImageVisualProperty.WrapModeV, new PropertyValue((int)value));
893             }
894         }
895
896         /// <summary>
897         /// Get attribues, it is abstract function and must be override.
898         /// </summary>
899         /// <since_tizen> 6 </since_tizen>
900         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
901         [EditorBrowsable(EditorBrowsableState.Never)]
902         protected override ViewStyle GetViewStyle()
903         {
904             return new ImageViewStyle();
905         }
906
907         internal void SetImage(string url, Uint16Pair size)
908         {
909             if(url.Contains(".json"))
910             {
911                 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
912                 return;
913             }
914
915             Interop.ImageView.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
916             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
917                         
918             ResourceUrl = url;
919         }
920
921         internal ViewResourceReadySignal ResourceReadySignal(View view)
922         {
923             ViewResourceReadySignal ret = new ViewResourceReadySignal(Interop.View.ResourceReadySignal(View.getCPtr(view)), false);
924             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
925             return ret;
926         }
927
928         internal ResourceLoadingStatusType GetResourceStatus()
929         {
930             return (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
931         }
932
933         internal static readonly BindableProperty ResourceUrlSelectorProperty = BindableProperty.Create("ResourceUrlSelector", typeof(Selector<string>), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
934         {
935             var imageView = (ImageView)bindable;
936             imageView.resourceUrlSelector.Clone((Selector<string>)newValue);
937         },
938         defaultValueCreator: (bindable) =>
939         {
940             var imageView = (ImageView)bindable;
941             return imageView.resourceUrlSelector;
942         });
943         private TriggerableSelector<string> _resourceUrlSelector;
944         private TriggerableSelector<string> resourceUrlSelector
945         {
946             get
947             {
948                 if (null == _resourceUrlSelector)
949                 {
950                     _resourceUrlSelector = new TriggerableSelector<string>(this, ResourceUrlProperty);
951                 }
952                 return _resourceUrlSelector;
953             }
954         }
955
956         internal static readonly BindableProperty BorderSelectorProperty = BindableProperty.Create("BorderSelector", typeof(Selector<Rectangle>), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
957         {
958             var imageView = (ImageView)bindable;
959             imageView.borderSelector.Clone((Selector<Rectangle>)newValue);
960         },
961         defaultValueCreator: (bindable) =>
962         {
963             var imageView = (ImageView)bindable;
964             return imageView.borderSelector;
965         });
966         private TriggerableSelector<Rectangle> _borderSelector;
967         private TriggerableSelector<Rectangle> borderSelector
968         {
969             get
970             {
971                 if (null == _borderSelector)
972                 {
973                     _borderSelector = new TriggerableSelector<Rectangle>(this, BorderProperty);
974                 }
975                 return _borderSelector;
976             }
977         }
978
979         /// <summary>
980         /// you can override it to clean-up your own resources.
981         /// </summary>
982         /// <param name="type">DisposeTypes</param>
983         /// <since_tizen> 3 </since_tizen>
984         protected override void Dispose(DisposeTypes type)
985         {
986             if (disposed)
987             {
988                 return;
989             }
990
991             if (type == DisposeTypes.Explicit)
992             {
993                 //Called by User
994                 //Release your own managed resources here.
995                 //You should release all of your own disposable objects here.
996                 _border?.Dispose();
997                 _border = null;
998             }
999
1000             base.Dispose(type);
1001         }
1002
1003         /// This will not be public opened.
1004         [EditorBrowsable(EditorBrowsableState.Never)]
1005         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1006         {
1007             Interop.ImageView.delete_ImageView(swigCPtr);
1008         }
1009
1010         // Callback for View ResourceReady signal
1011         private void OnResourceReady(IntPtr data)
1012         {
1013             ResourceReadyEventArgs e = new ResourceReadyEventArgs();
1014             if (data != null)
1015             {
1016                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1017             }
1018
1019             if (_resourceReadyEventHandler != null)
1020             {
1021                 _resourceReadyEventHandler(this, e);
1022             }
1023         }
1024
1025         private void UpdateImageMap(PropertyMap fromMap)
1026         {
1027             PropertyMap imageMap = new PropertyMap();
1028             Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
1029             imageMap.Merge(fromMap);
1030                         
1031             SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
1032         }
1033                 
1034         private void UpdateImage(int key, PropertyValue value)
1035         {
1036             PropertyMap temp = new PropertyMap();
1037
1038             if (_resourceUrl == "")
1039             {
1040                 temp.Insert(ImageVisualProperty.URL, new PropertyValue(_resourceUrl));
1041                 SetProperty(ImageView.Property.IMAGE, new PropertyValue(temp));
1042                 return;
1043             }
1044
1045             if (_border == null)
1046             {
1047                 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
1048             }
1049             else
1050             {
1051                 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
1052                 temp.Insert(NpatchImageVisualProperty.Border, new PropertyValue(_border));
1053             }
1054
1055             temp.Insert(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue(_synchronosLoading));
1056
1057             if (value != null)
1058             {
1059                 temp.Insert(key, value);
1060             }
1061
1062             UpdateImageMap(temp);
1063
1064             temp.Dispose();
1065             temp = null;
1066         }
1067
1068
1069         private void OnResourceLoaded(IntPtr view)
1070         {
1071             ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
1072             e.Status = (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
1073
1074             if (_resourceLoadedEventHandler != null)
1075             {
1076                 _resourceLoadedEventHandler(this, e);
1077             }
1078         }
1079
1080         /// <summary>
1081         /// Event arguments of resource ready.
1082         /// </summary>
1083         /// <since_tizen> 3 </since_tizen>
1084         public class ResourceReadyEventArgs : EventArgs
1085         {
1086             private View _view;
1087
1088             /// <summary>
1089             /// The view whose resource is ready.
1090             /// </summary>
1091             /// <since_tizen> 3 </since_tizen>
1092             public View View
1093             {
1094                 get
1095                 {
1096                     return _view;
1097                 }
1098                 set
1099                 {
1100                     _view = value;
1101                 }
1102             }
1103         }
1104
1105         internal class ResourceLoadedEventArgs : EventArgs
1106         {
1107             private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1108             public ResourceLoadingStatusType Status
1109             {
1110                 get
1111                 {
1112                     return status;
1113                 }
1114                 set
1115                 {
1116                     status = value;
1117                 }
1118             }
1119         }
1120
1121         internal new class Property
1122         {
1123             internal static readonly int IMAGE = Interop.ImageView.ImageView_Property_IMAGE_get();
1124             internal static readonly int PRE_MULTIPLIED_ALPHA = Interop.ImageView.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
1125             internal static readonly int PIXEL_AREA = Interop.ImageView.ImageView_Property_PIXEL_AREA_get();
1126             internal static readonly int ACTION_RELOAD = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_RELOAD_get();
1127             internal static readonly int ACTION_PLAY = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_PLAY_get();
1128             internal static readonly int ACTION_PAUSE = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_PAUSE_get();
1129             internal static readonly int ACTION_STOP = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_STOP_get();
1130         }
1131
1132         private enum ImageType
1133         {
1134             /// <summary>
1135             /// For Normal Image.
1136             /// </summary>
1137             Normal = 0,
1138
1139             /// <summary>
1140             /// For normal image, with synchronous loading and orientation correction property
1141             /// </summary>
1142             Specific = 1,
1143
1144             /// <summary>
1145             /// For nine-patch image
1146             /// </summary>
1147             Npatch = 2,
1148         }
1149
1150         private void OnBorderChanged(int x, int y, int width, int height)
1151         {
1152             Border = new Rectangle(x, y, width, height);
1153         }
1154         private void OnPixelAreaChanged(float x, float y, float z, float w)
1155         {
1156             PixelArea = new RelativeVector4(x, y, z, w);
1157         }
1158     }
1159 }