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