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