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