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