c622cb41a9386b5e9ef141882141c65366ca044c
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ImageView.cs
1 /*
2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17 using System;
18 using System.Runtime.InteropServices;
19 using System.ComponentModel;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.BaseComponents
23 {
24
25     /// <summary>
26     /// ImageView is a class for displaying an image resource.<br />
27     /// An instance of ImageView can be created using a URL or an image instance.<br />
28     /// </summary>
29     /// <since_tizen> 3 </since_tizen>
30     public class ImageView : View
31     {
32         static ImageView() { }
33
34         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
35         [EditorBrowsable(EditorBrowsableState.Never)]
36         public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create(nameof(ImageView.ResourceUrl), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
37         {
38             var imageView = (ImageView)bindable;
39             string url = (string)newValue;
40             url = (url == null ? "" : url);
41             if (imageView.IsCreateByXaml && url.Contains("*Resource*"))
42             {
43                 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
44                 url = url.Replace("*Resource*", resource);
45             }
46             imageView._resourceUrl = url;
47             imageView.UpdateImage(ImageVisualProperty.URL, new PropertyValue(url));
48         },
49         defaultValueCreator: (bindable) =>
50         {
51             var imageView = (ImageView)bindable;
52             string ret = "";
53                         
54             PropertyMap imageMap = new PropertyMap();
55             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
56             imageMap.Find(ImageVisualProperty.URL)?.Get(out ret);
57             return ret;
58         });
59
60         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
61         [EditorBrowsable(EditorBrowsableState.Never)]
62         public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(ImageView.Image), typeof(PropertyMap), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
63         {
64             var imageView = (ImageView)bindable;
65             if (newValue != null)
66             {
67                 PropertyMap map = (PropertyMap)newValue;
68                 if (imageView.IsCreateByXaml)
69                 {
70                     string url = "", alphaMaskURL = "", auxiliaryImageURL = "";
71                     string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
72                     PropertyValue urlValue = map.Find(NDalic.IMAGE_VISUAL_URL);
73                     bool ret = false;
74                     if (urlValue != null) ret = urlValue.Get(out url);
75                     PropertyMap mmap = new PropertyMap();
76                     if (ret && url.Contains("*Resource*"))
77                     {
78                         url = url.Replace("*Resource*", resource);
79                         mmap.Insert(NDalic.IMAGE_VISUAL_URL, new PropertyValue(url));
80                     }
81
82                     ret = false;
83                     PropertyValue alphaMaskUrlValue = map.Find(NDalic.IMAGE_VISUAL_ALPHA_MASK_URL);
84                     if (alphaMaskUrlValue != null) ret = alphaMaskUrlValue.Get(out alphaMaskURL);
85                     if (ret && alphaMaskURL.Contains("*Resource*"))
86                     {
87                         alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource);
88                         mmap.Insert(NDalic.IMAGE_VISUAL_URL, new PropertyValue(alphaMaskURL));
89                     }
90
91                     ret = false;
92                     PropertyValue auxiliaryImageURLValue = map.Find(NDalic.IMAGE_VISUAL_AUXILIARY_IMAGE_URL);
93                     if (auxiliaryImageURLValue != null) ret = auxiliaryImageURLValue.Get(out auxiliaryImageURL);
94                     if (ret && auxiliaryImageURL.Contains("*Resource*"))
95                     {
96                         auxiliaryImageURL = auxiliaryImageURL.Replace("*Resource*", resource);
97                         mmap.Insert(NDalic.IMAGE_VISUAL_AUXILIARY_IMAGE_URL, new PropertyValue(auxiliaryImageURL));
98                     }
99
100                     map.Merge(mmap);
101                 }
102                 if (imageView._border == null)
103                 {
104                     Tizen.NUI.Object.SetProperty(imageView.swigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
105                 }
106             }
107         },
108         defaultValueCreator: (bindable) =>
109         {
110             var imageView = (ImageView)bindable;
111             if (imageView._border == null)
112             {
113                 PropertyMap temp = new PropertyMap();
114                 Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(temp);
115                 return temp;
116             }
117             else
118             {
119                 return null;
120             }
121         });
122
123         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
124         [EditorBrowsable(EditorBrowsableState.Never)]
125         public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create("PreMultipliedAlpha", typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
126         {
127             var imageView = (ImageView)bindable;
128             if (newValue != null)
129             {
130                 Tizen.NUI.Object.SetProperty(imageView.swigCPtr, ImageView.Property.PRE_MULTIPLIED_ALPHA, new Tizen.NUI.PropertyValue((bool)newValue));
131             }
132         },
133         defaultValueCreator: (bindable) =>
134         {
135             var imageView = (ImageView)bindable;
136             bool temp = false;
137             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.PRE_MULTIPLIED_ALPHA).Get(out temp);
138             return temp;
139         });
140
141         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
142         [EditorBrowsable(EditorBrowsableState.Never)]
143         public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create("PixelArea", typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
144         {
145             var imageView = (ImageView)bindable;
146             if (newValue != null)
147             {
148                 Tizen.NUI.Object.SetProperty(imageView.swigCPtr, ImageView.Property.PIXEL_AREA, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
149             }
150         },
151         defaultValueCreator: (bindable) =>
152         {
153             var imageView = (ImageView)bindable;
154             Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
155             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.PIXEL_AREA).Get(temp);
156             RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
157             return relativeTemp;
158         });
159
160         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
161         [EditorBrowsable(EditorBrowsableState.Never)]
162         public static readonly BindableProperty BorderProperty = BindableProperty.Create("Border", typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
163         {
164             if(newValue != null)
165             {
166                 var imageView = (ImageView)bindable;
167                 imageView._border = (Rectangle)newValue;
168                 imageView.UpdateImage(NpatchImageVisualProperty.Border, new PropertyValue(imageView._border));
169             }
170         },
171         defaultValueCreator: (bindable) =>
172         {
173             var imageView = (ImageView)bindable;
174             return imageView._border;
175         });
176
177         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
178         [EditorBrowsable(EditorBrowsableState.Never)]
179         public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create("BorderOnly", typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
180         {
181             var imageView = (ImageView)bindable;
182             if (newValue != null)
183             {
184                 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
185             }
186         },
187         defaultValueCreator: (bindable) =>
188         {
189             var imageView = (ImageView)bindable;
190             bool ret = false;
191             PropertyMap imageMap = new PropertyMap();
192             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
193             imageMap.Find(ImageVisualProperty.BorderOnly)?.Get(out ret);
194             return ret;
195         });
196
197         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
198         [EditorBrowsable(EditorBrowsableState.Never)]
199         public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create("SynchronosLoading", typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
200         {
201             var imageView = (ImageView)bindable;
202             if (newValue != null)
203             {
204                 imageView._synchronosLoading = (bool) newValue;
205                 imageView.UpdateImage(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
206             }
207         },
208         defaultValueCreator: (bindable) =>
209         {
210             var imageView = (ImageView)bindable;
211             return imageView._synchronosLoading;
212         });
213
214         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
215         [EditorBrowsable(EditorBrowsableState.Never)]
216         public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create("OrientationCorrection", typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
217         {
218             var imageView = (ImageView)bindable;
219             if (newValue != null)
220             {
221                 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
222             }
223         },
224         defaultValueCreator: (bindable) =>
225         {
226             var imageView = (ImageView)bindable;
227             
228             bool ret = false;
229             PropertyMap imageMap = new PropertyMap();
230             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
231             imageMap?.Find(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
232
233             return ret;
234         });
235
236         private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
237         private ResourceReadyEventCallbackType _resourceReadyEventCallback;
238         private EventHandler<ResourceLoadedEventArgs> _resourceLoadedEventHandler;
239         private _resourceLoadedCallbackType _resourceLoadedCallback;
240
241         private Rectangle _border;
242         private string _resourceUrl = "";
243         private bool _synchronosLoading = false;
244         private string _alphaMaskUrl = null;
245         private int _desired_width = -1;
246         private int _desired_height = -1;
247
248         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
249         [EditorBrowsable(EditorBrowsableState.Never)]
250         public ImageViewStyle Style => ViewStyle as ImageViewStyle;
251
252         /// <summary>
253         /// Creates an initialized ImageView.
254         /// </summary>
255         /// <since_tizen> 3 </since_tizen>
256         public ImageView() : this(Interop.ImageView.ImageView_New__SWIG_0(), true)
257         {
258             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259         }
260
261         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
262         [EditorBrowsable(EditorBrowsableState.Never)]
263         public ImageView(ViewStyle viewStyle) : this(Interop.ImageView.ImageView_New__SWIG_0(), true, viewStyle)
264         {
265         }
266
267         /// <summary>
268         /// Creates an initialized ImageView with setting the status of shown or hidden.
269         /// </summary>
270         /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
271         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
272         [EditorBrowsable(EditorBrowsableState.Never)]
273         public ImageView(bool shown) : this(Interop.ImageView.ImageView_New__SWIG_0(), true)
274         {
275             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276             SetVisible(shown);
277         }
278
279         /// <summary>
280         /// Creates an initialized ImageView from a URL to an image resource.<br />
281         /// If the string is empty, ImageView will not display anything.<br />
282         /// </summary>
283         /// <param name="url">The URL of the image resource to display.</param>
284         /// <since_tizen> 3 </since_tizen>
285         public ImageView(string url) : this(Interop.ImageView.ImageView_New__SWIG_2(url), true)
286         {
287             ResourceUrl = url;
288             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289
290         }
291
292         /// <summary>
293         /// Creates an initialized ImageView from a URL to an image resource with setting shown or hidden.
294         /// </summary>
295         /// <param name="url">The URL of the image resource to display.</param>
296         /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
297         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
298         [EditorBrowsable(EditorBrowsableState.Never)]
299         public ImageView(string url, bool shown) : this(Interop.ImageView.ImageView_New__SWIG_2(url), true)
300         {
301             ResourceUrl = url;
302             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
303             SetVisible(shown);
304         }
305
306         internal ImageView(string url, Uint16Pair size, bool shown = true) : this(Interop.ImageView.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true)
307         {
308             ResourceUrl = url;
309             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310
311             if (!shown)
312             {
313                 SetVisible(false);
314             }
315         }
316
317         internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(Interop.ImageView.ImageView_SWIGUpcast(cPtr), cMemoryOwn, viewStyle)
318         {
319             if (!shown)
320             {
321                 SetVisible(false);
322             }
323         }
324
325         internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(Interop.ImageView.ImageView_SWIGUpcast(cPtr), cMemoryOwn)
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                 _alphaMaskUrl = ret;
733                 return ret;
734             }
735             set
736             {
737                 if (value == null)
738                 {
739                     value = "";
740                 }
741
742                 _alphaMaskUrl = value;
743                 UpdateImage(ImageVisualProperty.AlphaMaskURL, new PropertyValue(value));
744             }
745         }
746
747
748         /// <summary>
749         ///  Whether to crop image to mask or scale mask to fit image.
750         /// </summary>
751         /// <since_tizen> 6 </since_tizen>
752         public bool CropToMask
753         {
754             get
755             {
756                 bool ret = false;
757                 PropertyMap imageMap = new PropertyMap();
758                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
759                 imageMap?.Find(ImageVisualProperty.CropToMask)?.Get(out ret);
760
761                 return ret;
762             }
763             set
764             {
765                 UpdateImage(ImageVisualProperty.CropToMask, new PropertyValue(value));
766             }
767         }
768
769         internal VisualFittingModeType CovertFittingModetoVisualFittingMode(FittingModeType value)
770         {
771             switch(value)
772             {
773                 case FittingModeType.ShrinkToFit:
774                     return VisualFittingModeType.FitKeepAspectRatio;
775                 case FittingModeType.ScaleToFill:
776                     return VisualFittingModeType.OverFitKeepAspectRatio;
777                 case FittingModeType.Center:
778                     return VisualFittingModeType.Center;
779                 case FittingModeType.Fill:
780                     return VisualFittingModeType.Fill;
781                 case FittingModeType.FitHeight:
782                     return VisualFittingModeType.FitHeight;
783                 case FittingModeType.FitWidth:
784                     return VisualFittingModeType.FitHeight;
785                 default:
786                     return VisualFittingModeType.Fill;
787             }
788         }
789
790         internal FittingModeType ConvertVisualFittingModetoFittingMode(VisualFittingModeType value)
791         {
792             switch(value)
793             {
794                 case VisualFittingModeType.FitKeepAspectRatio:
795                     return FittingModeType.ShrinkToFit;
796                 case VisualFittingModeType.OverFitKeepAspectRatio:
797                     return FittingModeType.ScaleToFill;
798                 case VisualFittingModeType.Center:
799                     return FittingModeType.Center;
800                 case VisualFittingModeType.Fill:
801                     return FittingModeType.Fill;
802                 case VisualFittingModeType.FitHeight:
803                     return FittingModeType.FitHeight;
804                 case VisualFittingModeType.FitWidth:
805                     return FittingModeType.FitHeight;
806                 default:
807                     return FittingModeType.ShrinkToFit;
808             }
809         }
810
811         /// <summary>
812         /// Gets or sets fitting options used when resizing images to fit.<br />
813         /// If not supplied, the default is FittingModeType.Fill.<br />
814         /// For normal quad images only.<br />
815         /// Optional.
816         /// </summary>
817         /// <since_tizen> 6 </since_tizen>
818         [EditorBrowsable(EditorBrowsableState.Never)]
819         public FittingModeType FittingMode
820         {
821             get
822             {
823                 int ret = (int)VisualFittingModeType.Fill;
824                 PropertyMap imageMap = new PropertyMap();
825                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
826                 imageMap?.Find(Visual.Property.VisualFittingMode)?.Get(out ret);
827                 return ConvertVisualFittingModetoFittingMode((VisualFittingModeType)ret);
828             }
829             set
830             {
831                 VisualFittingModeType ret = CovertFittingModetoVisualFittingMode(value);
832                 UpdateImage(Visual.Property.VisualFittingMode, new PropertyValue((int) ret));
833             }
834         }
835
836
837
838         /// <summary>
839         /// Gets or sets the desired image width.<br />
840         /// If not specified, the actual image width is used.<br />
841         /// For normal quad images only.<br />
842         /// Optional.
843         /// </summary>
844         /// <since_tizen> 6 </since_tizen>
845         [EditorBrowsable(EditorBrowsableState.Never)]
846         public int DesiredWidth
847         {
848             get
849             {
850                 PropertyMap imageMap = new PropertyMap();
851                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
852                 imageMap?.Find(ImageVisualProperty.DesiredWidth)?.Get(out _desired_width);
853
854                 return _desired_width;
855             }
856             set
857             {
858                 UpdateImage(ImageVisualProperty.DesiredWidth, new PropertyValue(value));
859                 _desired_width = value;
860             }
861         }
862
863         /// <summary>
864         /// Gets or sets the desired image height.<br />
865         /// If not specified, the actual image height is used.<br />
866         /// For normal quad images only.<br />
867         /// Optional.
868         /// </summary>
869         /// <since_tizen> 6 </since_tizen>
870         [EditorBrowsable(EditorBrowsableState.Never)]
871         public int DesiredHeight
872         {
873             get
874             {
875                 PropertyMap imageMap = new PropertyMap();
876                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
877                 imageMap?.Find(ImageVisualProperty.DesiredHeight)?.Get(out _desired_height);
878
879                 return _desired_height;
880             }
881             set
882             {
883                 UpdateImage(ImageVisualProperty.DesiredHeight, new PropertyValue(value));
884                 _desired_height = value;
885             }
886         }
887
888
889         /// <summary>
890         /// Gets or sets the wrap mode for the u coordinate.<br />
891         /// It decides how the texture should be sampled when the u coordinate exceeds the range of 0.0 to 1.0.<br />
892         /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
893         /// For normal quad images only.<br />
894         /// Optional.
895         /// </summary>
896         /// <since_tizen> 6 </since_tizen>
897         [EditorBrowsable(EditorBrowsableState.Never)]
898         public WrapModeType WrapModeU
899         {
900             get
901             {
902                 int ret = (int)WrapModeType.Default;
903                 PropertyMap imageMap = new PropertyMap();
904                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
905                 imageMap?.Find(ImageVisualProperty.WrapModeU)?.Get(out ret);
906
907                 return (WrapModeType)ret;
908             }
909             set
910             {
911                 UpdateImage(ImageVisualProperty.WrapModeU, new PropertyValue((int)value));
912             }
913         }
914
915         /// <summary>
916         /// Gets or sets the wrap mode for the v coordinate.<br />
917         /// It decides how the texture should be sampled when the v coordinate exceeds the range of 0.0 to 1.0.<br />
918         /// 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 />
919         /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
920         /// For normal quad images only.
921         /// Optional.
922         /// </summary>
923         /// <since_tizen> 6 </since_tizen>
924         [EditorBrowsable(EditorBrowsableState.Never)]
925         public WrapModeType WrapModeV
926         {
927             get
928             {
929                 int ret = (int)WrapModeType.Default;
930                 PropertyMap imageMap = new PropertyMap();
931                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
932                 imageMap?.Find(ImageVisualProperty.WrapModeV)?.Get(out ret);
933
934                 return (WrapModeType)ret;
935             }
936             set
937             {
938                 UpdateImage(ImageVisualProperty.WrapModeV, new PropertyValue((int)value));
939             }
940         }
941
942         /// <summary>
943         /// Get attribues, it is abstract function and must be override.
944         /// </summary>
945         /// <since_tizen> 6 </since_tizen>
946         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
947         [EditorBrowsable(EditorBrowsableState.Never)]
948         protected override ViewStyle GetViewStyle()
949         {
950             return new ImageViewStyle();
951         }
952
953         internal void SetImage(string url, Uint16Pair size)
954         {
955             if(url.Contains(".json"))
956             {
957                 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
958                 return;
959             }
960
961             Interop.ImageView.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
962             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
963                         
964             ResourceUrl = url;
965         }
966
967         internal ViewResourceReadySignal ResourceReadySignal(View view)
968         {
969             ViewResourceReadySignal ret = new ViewResourceReadySignal(Interop.View.ResourceReadySignal(View.getCPtr(view)), false);
970             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
971             return ret;
972         }
973
974         internal override void UpdateCornerRadius(float value, bool needToListenStateChanged)
975         {
976             base.UpdateCornerRadius(value, needToListenStateChanged);
977
978             UpdateImage(0, null);
979         }
980
981         internal ResourceLoadingStatusType GetResourceStatus()
982         {
983             return (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
984         }
985
986         internal static readonly BindableProperty ResourceUrlSelectorProperty = BindableProperty.Create("ResourceUrlSelector", typeof(Selector<string>), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
987         {
988             var imageView = (ImageView)bindable;
989             imageView.resourceUrlSelector.Clone((Selector<string>)newValue);
990         },
991         defaultValueCreator: (bindable) =>
992         {
993             var imageView = (ImageView)bindable;
994             return imageView.resourceUrlSelector;
995         });
996         private TriggerableSelector<string> _resourceUrlSelector;
997         private TriggerableSelector<string> resourceUrlSelector
998         {
999             get
1000             {
1001                 if (null == _resourceUrlSelector)
1002                 {
1003                     _resourceUrlSelector = new TriggerableSelector<string>(this, ResourceUrlProperty);
1004                 }
1005                 return _resourceUrlSelector;
1006             }
1007         }
1008
1009         internal static readonly BindableProperty BorderSelectorProperty = BindableProperty.Create("BorderSelector", typeof(Selector<Rectangle>), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
1010         {
1011             var imageView = (ImageView)bindable;
1012             imageView.borderSelector.Clone((Selector<Rectangle>)newValue);
1013         },
1014         defaultValueCreator: (bindable) =>
1015         {
1016             var imageView = (ImageView)bindable;
1017             return imageView.borderSelector;
1018         });
1019         private TriggerableSelector<Rectangle> _borderSelector;
1020         private TriggerableSelector<Rectangle> borderSelector
1021         {
1022             get
1023             {
1024                 if (null == _borderSelector)
1025                 {
1026                     _borderSelector = new TriggerableSelector<Rectangle>(this, BorderProperty);
1027                 }
1028                 return _borderSelector;
1029             }
1030         }
1031
1032         /// <summary>
1033         /// you can override it to clean-up your own resources.
1034         /// </summary>
1035         /// <param name="type">DisposeTypes</param>
1036         /// <since_tizen> 3 </since_tizen>
1037         protected override void Dispose(DisposeTypes type)
1038         {
1039             if (disposed)
1040             {
1041                 return;
1042             }
1043
1044             if (type == DisposeTypes.Explicit)
1045             {
1046                 //Called by User
1047                 //Release your own managed resources here.
1048                 //You should release all of your own disposable objects here.
1049                 _border?.Dispose();
1050                 _border = null;
1051             }
1052
1053             base.Dispose(type);
1054         }
1055
1056         /// This will not be public opened.
1057         [EditorBrowsable(EditorBrowsableState.Never)]
1058         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1059         {
1060             Interop.ImageView.delete_ImageView(swigCPtr);
1061         }
1062
1063         // Callback for View ResourceReady signal
1064         private void OnResourceReady(IntPtr data)
1065         {
1066             ResourceReadyEventArgs e = new ResourceReadyEventArgs();
1067             if (data != null)
1068             {
1069                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1070             }
1071
1072             if (_resourceReadyEventHandler != null)
1073             {
1074                 _resourceReadyEventHandler(this, e);
1075             }
1076         }
1077
1078         private void UpdateImageMap(PropertyMap fromMap)
1079         {
1080             PropertyMap imageMap = new PropertyMap();
1081             Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
1082             imageMap.Merge(fromMap);
1083                         
1084             SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
1085         }
1086                 
1087         private void UpdateImage(int key, PropertyValue value)
1088         {
1089             PropertyMap temp = new PropertyMap();
1090
1091             if(_alphaMaskUrl != null)
1092             {
1093                 temp.Insert(ImageVisualProperty.AlphaMaskURL, new PropertyValue(_alphaMaskUrl));
1094             }
1095
1096             if (_resourceUrl == "")
1097             {
1098                 temp.Insert(ImageVisualProperty.URL, new PropertyValue(_resourceUrl));
1099                 SetProperty(ImageView.Property.IMAGE, new PropertyValue(temp));
1100                 return;
1101             }
1102
1103             if (_border == null)
1104             {
1105                 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
1106             }
1107             else
1108             {
1109                 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
1110                 temp.Insert(NpatchImageVisualProperty.Border, new PropertyValue(_border));
1111             }
1112
1113             temp.Insert(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue(_synchronosLoading));
1114
1115             if (backgroundExtraData != null && backgroundExtraData.CornerRadius > 0)
1116             {
1117                 temp.Insert(Visual.Property.CornerRadius, new PropertyValue(backgroundExtraData.CornerRadius));
1118             }
1119
1120             if (value != null)
1121             {
1122                 temp.Insert(key, value);
1123             }
1124
1125             // Do Fitting Buffer when desired dimension is set
1126             if( _desired_width != -1 && _desired_height != -1)
1127             {
1128                 if(_resourceUrl != null)
1129                 {
1130                   Size2D imageSize = ImageLoading.GetOriginalImageSize(_resourceUrl);
1131
1132                   int ret_width,ret_height;
1133                   if( imageSize.Width > imageSize.Height)
1134                   {
1135                       ret_width = _desired_width;
1136                       ret_height = imageSize.Height * _desired_height /(imageSize.Width);
1137                   }
1138                   else
1139                   {
1140                       ret_width = imageSize.Width*_desired_width/(imageSize.Height);
1141                       ret_height = _desired_height;
1142
1143                   }
1144                   temp.Insert(ImageVisualProperty.DesiredWidth, new PropertyValue((int)ret_width));
1145                   temp.Insert(ImageVisualProperty.DesiredHeight, new PropertyValue((int)ret_height));
1146                   temp.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int) FittingModeType.ShrinkToFit));
1147                 }
1148             }
1149
1150             UpdateImageMap(temp);
1151
1152             temp.Dispose();
1153             temp = null;
1154         }
1155
1156
1157         private void OnResourceLoaded(IntPtr view)
1158         {
1159             ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
1160             e.Status = (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
1161
1162             if (_resourceLoadedEventHandler != null)
1163             {
1164                 _resourceLoadedEventHandler(this, e);
1165             }
1166         }
1167
1168         /// <summary>
1169         /// Event arguments of resource ready.
1170         /// </summary>
1171         /// <since_tizen> 3 </since_tizen>
1172         public class ResourceReadyEventArgs : EventArgs
1173         {
1174             private View _view;
1175
1176             /// <summary>
1177             /// The view whose resource is ready.
1178             /// </summary>
1179             /// <since_tizen> 3 </since_tizen>
1180             public View View
1181             {
1182                 get
1183                 {
1184                     return _view;
1185                 }
1186                 set
1187                 {
1188                     _view = value;
1189                 }
1190             }
1191         }
1192
1193         internal class ResourceLoadedEventArgs : EventArgs
1194         {
1195             private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1196             public ResourceLoadingStatusType Status
1197             {
1198                 get
1199                 {
1200                     return status;
1201                 }
1202                 set
1203                 {
1204                     status = value;
1205                 }
1206             }
1207         }
1208
1209         internal new class Property
1210         {
1211             internal static readonly int IMAGE = Interop.ImageView.ImageView_Property_IMAGE_get();
1212             internal static readonly int PRE_MULTIPLIED_ALPHA = Interop.ImageView.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
1213             internal static readonly int PIXEL_AREA = Interop.ImageView.ImageView_Property_PIXEL_AREA_get();
1214             internal static readonly int ACTION_RELOAD = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_RELOAD_get();
1215             internal static readonly int ACTION_PLAY = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_PLAY_get();
1216             internal static readonly int ACTION_PAUSE = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_PAUSE_get();
1217             internal static readonly int ACTION_STOP = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_STOP_get();
1218         }
1219
1220         private enum ImageType
1221         {
1222             /// <summary>
1223             /// For Normal Image.
1224             /// </summary>
1225             Normal = 0,
1226
1227             /// <summary>
1228             /// For normal image, with synchronous loading and orientation correction property
1229             /// </summary>
1230             Specific = 1,
1231
1232             /// <summary>
1233             /// For nine-patch image
1234             /// </summary>
1235             Npatch = 2,
1236         }
1237
1238         private void OnBorderChanged(int x, int y, int width, int height)
1239         {
1240             Border = new Rectangle(x, y, width, height);
1241         }
1242         private void OnPixelAreaChanged(float x, float y, float z, float w)
1243         {
1244             PixelArea = new RelativeVector4(x, y, z, w);
1245         }
1246     }
1247 }