[NUI] TCSACR-226 code change (#1032)
[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         /// <since_tizen> 3 </since_tizen>
495         public RelativeVector4 PixelArea
496         {
497             get
498             {
499                 return (RelativeVector4)GetValue(PixelAreaProperty);
500             }
501             set
502             {
503                 SetValue(PixelAreaProperty, value);
504                 NotifyPropertyChanged();
505             }
506         }
507
508         /// <summary>
509         /// The border of the image in the order: left, right, bottom, top.<br />
510         /// If set, ImageMap will be ignored.<br />
511         /// For N-Patch images only.<br />
512         /// Optional.
513         /// </summary>
514         /// <since_tizen> 3 </since_tizen>
515         public Rectangle Border
516         {
517             get
518             {
519                 return (Rectangle)GetValue(BorderProperty);
520             }
521             set
522             {
523                 SetValue(BorderProperty, value);
524                 NotifyPropertyChanged();
525             }
526         }
527
528         /// <summary>
529         /// Gets or sets whether to draw the borders only (if true).<br />
530         /// If not specified, the default is false.<br />
531         /// For N-Patch images only.<br />
532         /// Optional.
533         /// </summary>
534         /// <since_tizen> 3 </since_tizen>
535         public bool BorderOnly
536         {
537             get
538             {
539                 return (bool)GetValue(BorderOnlyProperty);
540             }
541             set
542             {
543                 SetValue(BorderOnlyProperty, value);
544                 NotifyPropertyChanged();
545             }
546         }
547
548         /// <summary>
549         /// Gets or sets whether to synchronos loading the resourceurl of image.<br />
550         /// </summary>
551         /// <since_tizen> 3 </since_tizen>
552         public bool SynchronosLoading
553         {
554             get
555             {
556                 return (bool)GetValue(SynchronosLoadingProperty);
557             }
558             set
559             {
560                 SetValue(SynchronosLoadingProperty, value);
561                 NotifyPropertyChanged();
562             }
563         }
564
565         /// <summary>
566         /// Gets or sets whether to automatically correct the orientation of an image.<br />
567         /// </summary>
568         /// <since_tizen> 5 </since_tizen>
569         public bool OrientationCorrection
570         {
571             get
572             {
573                 return (bool)GetValue(OrientationCorrectionProperty);
574             }
575             set
576             {
577                 SetValue(OrientationCorrectionProperty, value);
578                 NotifyPropertyChanged();
579             }
580         }
581
582         /// <summary>
583         /// Gets the loading state of the visual resource.
584         /// </summary>
585         /// <since_tizen> 5 </since_tizen>
586         public ImageView.LoadingStatusType LoadingStatus
587         {
588             get
589             {
590                 return (ImageView.LoadingStatusType)Interop.View.View_GetVisualResourceStatus(swigCPtr, (int)Property.IMAGE);
591             }
592         }
593
594         /// <summary>
595         /// Downcasts a handle to imageView handle.
596         /// </summary>
597         /// Please do not use! this will be deprecated!
598         /// Instead please use as keyword.
599         /// <since_tizen> 3 </since_tizen>
600         [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
601         "Like: " +
602         "BaseHandle handle = new ImageView(imagePath); " +
603         "ImageView image = handle as ImageView")]
604         [EditorBrowsable(EditorBrowsableState.Never)]
605         public static ImageView DownCast(BaseHandle handle)
606         {
607             ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
608             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
609             return ret;
610         }
611
612         /// <summary>
613         /// Sets this ImageView from the given URL.<br />
614         /// If the URL is empty, ImageView will not display anything.<br />
615         /// </summary>
616         /// <param name="url">The URL to the image resource to display.</param>
617         /// <since_tizen> 3 </since_tizen>
618         public void SetImage(string url)
619         {
620             if(url.Contains(".json"))
621             {
622                 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
623                 return;
624             }
625
626             Interop.ImageView.ImageView_SetImage__SWIG_1(swigCPtr, url);
627             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
628
629             ResourceUrl = url;
630         }
631
632         /// <summary>
633         /// Queries if all resources required by a control are loaded and ready.<br />
634         /// Most resources are only loaded when the control is placed on the stage.<br />
635         /// True if the resources are loaded and ready, false otherwise.<br />
636         /// </summary>
637         /// <since_tizen> 3 </since_tizen>
638         public new bool IsResourceReady()
639         {
640             bool ret = Interop.View.IsResourceReady(swigCPtr);
641             if (NDalicPINVOKE.SWIGPendingException.Pending)
642                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
643             return ret;
644         }
645
646         /// <summary>
647         /// Forcefully reloads the image. All the visuals using this image will reload to the latest image.
648         /// </summary>
649         /// <since_tizen> 5 </since_tizen>
650         public void Reload()
651         {
652             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_RELOAD, new PropertyValue(0));
653         }
654
655         /// <summary>
656         /// Plays the animated GIF. This is also the default playback mode.
657         /// </summary>
658         /// <since_tizen> 5 </since_tizen>
659         public void Play()
660         {
661             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_PLAY, new PropertyValue(0));
662         }
663
664         /// <summary>
665         /// Pauses the animated GIF.
666         /// </summary>
667         /// <since_tizen> 5 </since_tizen>
668         public void Pause()
669         {
670             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_PAUSE, new PropertyValue(0));
671         }
672
673         /// <summary>
674         /// Stops the animated GIF.
675         /// </summary>
676         /// <since_tizen> 5 </since_tizen>
677         public void Stop()
678         {
679             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_STOP, new PropertyValue(0));
680         }
681
682         /// <summary>
683         /// Gets or sets the URL of the alpha mask.<br />
684         /// Optional.
685         /// </summary>
686         /// <since_tizen> 6</since_tizen>
687         [EditorBrowsable(EditorBrowsableState.Never)]
688         public string AlphaMaskURL
689         {
690             get
691             {
692                 string ret = "";
693                 PropertyMap imageMap = new PropertyMap();
694                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
695                 imageMap?.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out ret);
696
697                 return ret;
698             }
699             set
700             {
701                 if (value == null)
702                 {
703                     value = "";
704                 }
705
706                 UpdateImage(ImageVisualProperty.AlphaMaskURL, new PropertyValue(value));
707             }
708         }
709
710
711         /// <summary>
712         ///  Whether to crop image to mask or scale mask to fit image.
713         /// </summary>
714         /// <since_tizen> 6 </since_tizen>
715         public bool CropToMask
716         {
717             get
718             {
719                 bool ret = false;
720                 PropertyMap imageMap = new PropertyMap();
721                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
722                 imageMap?.Find(ImageVisualProperty.CropToMask)?.Get(out ret);
723
724                 return ret;
725             }
726             set
727             {
728                 UpdateImage(ImageVisualProperty.CropToMask, new PropertyValue(value));
729             }
730         }
731
732
733         /// <summary>
734         /// Gets or sets fitting options used when resizing images to fit the desired dimensions.<br />
735         /// If not supplied, the default is FittingModeType.ShrinkToFit.<br />
736         /// For normal quad images only.<br />
737         /// Optional.
738         /// </summary>
739         /// <since_tizen> 6 </since_tizen>
740         [EditorBrowsable(EditorBrowsableState.Never)]
741         public FittingModeType FittingMode
742         {
743             get
744             {
745                 int ret = (int)FittingModeType.ShrinkToFit;
746                 PropertyMap imageMap = new PropertyMap();
747                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
748                 imageMap?.Find(ImageVisualProperty.FittingMode)?.Get(out ret);
749
750                 return (FittingModeType)ret;
751             }
752             set
753             {
754                 UpdateImage(ImageVisualProperty.CropToMask, new PropertyValue((int)value));
755             }
756         }
757
758
759
760         /// <summary>
761         /// Gets or sets the desired image width.<br />
762         /// If not specified, the actual image width is used.<br />
763         /// For normal quad images only.<br />
764         /// Optional.
765         /// </summary>
766         /// <since_tizen> 6 </since_tizen>
767         [EditorBrowsable(EditorBrowsableState.Never)]
768         public int DesiredWidth
769         {
770             get
771             {
772                 int ret = -1;
773                 PropertyMap imageMap = new PropertyMap();
774                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
775                 imageMap?.Find(ImageVisualProperty.DesiredWidth)?.Get(out ret);
776
777                 return ret;
778             }
779             set
780             {
781                 UpdateImage(ImageVisualProperty.DesiredWidth, new PropertyValue(value));
782             }
783         }
784
785         /// <summary>
786         /// Gets or sets the desired image height.<br />
787         /// If not specified, the actual image height is used.<br />
788         /// For normal quad images only.<br />
789         /// Optional.
790         /// </summary>
791         /// <since_tizen> 6 </since_tizen>
792         [EditorBrowsable(EditorBrowsableState.Never)]
793         public int DesiredHeight
794         {
795             get
796             {
797                 int ret = -1;
798                 PropertyMap imageMap = new PropertyMap();
799                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
800                 imageMap?.Find(ImageVisualProperty.DesiredHeight)?.Get(out ret);
801
802                 return ret;
803             }
804             set
805             {
806                 UpdateImage(ImageVisualProperty.DesiredHeight, new PropertyValue(value));
807             }
808         }
809
810
811         /// <summary>
812         /// Gets or sets the wrap mode for the u coordinate.<br />
813         /// It decides how the texture should be sampled when the u coordinate exceeds the range of 0.0 to 1.0.<br />
814         /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
815         /// For normal quad images only.<br />
816         /// Optional.
817         /// </summary>
818         /// <since_tizen> 6 </since_tizen>
819         [EditorBrowsable(EditorBrowsableState.Never)]
820         public WrapModeType WrapModeU
821         {
822             get
823             {
824                 int ret = (int)WrapModeType.Default;
825                 PropertyMap imageMap = new PropertyMap();
826                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
827                 imageMap?.Find(ImageVisualProperty.WrapModeU)?.Get(out ret);
828
829                 return (WrapModeType)ret;
830             }
831             set
832             {
833                 UpdateImage(ImageVisualProperty.WrapModeU, new PropertyValue((int)value));
834             }
835         }
836
837         /// <summary>
838         /// Gets or sets the wrap mode for the v coordinate.<br />
839         /// It decides how the texture should be sampled when the v coordinate exceeds the range of 0.0 to 1.0.<br />
840         /// 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 />
841         /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
842         /// For normal quad images only.
843         /// Optional.
844         /// </summary>
845         /// <since_tizen> 6 </since_tizen>
846         [EditorBrowsable(EditorBrowsableState.Never)]
847         public WrapModeType WrapModeV
848         {
849             get
850             {
851                 int ret = (int)WrapModeType.Default;
852                 PropertyMap imageMap = new PropertyMap();
853                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
854                 imageMap?.Find(ImageVisualProperty.WrapModeV)?.Get(out ret);
855
856                 return (WrapModeType)ret;
857             }
858             set
859             {
860                 UpdateImage(ImageVisualProperty.WrapModeV, new PropertyValue((int)value));
861             }
862         }
863
864
865         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImageView obj)
866         {
867             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
868         }
869
870         internal void SetImage(string url, Uint16Pair size)
871         {
872             if(url.Contains(".json"))
873             {
874                 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
875                 return;
876             }
877
878             Interop.ImageView.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
879             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
880                         
881             ResourceUrl = url;
882         }
883
884         internal ViewResourceReadySignal ResourceReadySignal(View view)
885         {
886             ViewResourceReadySignal ret = new ViewResourceReadySignal(Interop.View.ResourceReadySignal(View.getCPtr(view)), false);
887             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
888             return ret;
889         }
890
891         internal ResourceLoadingStatusType GetResourceStatus()
892         {
893             return (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
894         }
895
896         /// <summary>
897         /// you can override it to clean-up your own resources.
898         /// </summary>
899         /// <param name="type">DisposeTypes</param>
900         /// <since_tizen> 3 </since_tizen>
901         protected override void Dispose(DisposeTypes type)
902         {
903             if (disposed)
904             {
905                 return;
906             }
907
908             if (type == DisposeTypes.Explicit)
909             {
910                 //Called by User
911                 //Release your own managed resources here.
912                 //You should release all of your own disposable objects here.
913                 _border?.Dispose();
914                 _border = null;
915             }
916
917             //Release your own unmanaged resources here.
918             //You should not access any managed member here except static instance.
919             //because the execution order of Finalizes is non-deterministic.
920
921             if (swigCPtr.Handle != global::System.IntPtr.Zero)
922             {
923                 if (swigCMemOwn)
924                 {
925                     swigCMemOwn = false;
926                     Interop.ImageView.delete_ImageView(swigCPtr);
927                 }
928                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
929             }
930
931             base.Dispose(type);
932         }
933
934         // Callback for View ResourceReady signal
935         private void OnResourceReady(IntPtr data)
936         {
937             ResourceReadyEventArgs e = new ResourceReadyEventArgs();
938             if (data != null)
939             {
940                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
941             }
942
943             if (_resourceReadyEventHandler != null)
944             {
945                 _resourceReadyEventHandler(this, e);
946             }
947         }
948
949         private void UpdateImageMap(PropertyMap fromMap)
950         {
951             PropertyMap imageMap = new PropertyMap();
952             Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
953             imageMap.Merge(fromMap);
954                         
955             SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
956         }
957                 
958         private void UpdateImage(int key, PropertyValue value)
959         {
960             PropertyMap temp = new PropertyMap();
961
962             if (_resourceUrl == "")
963             {
964                 temp.Insert(ImageVisualProperty.URL, new PropertyValue(_resourceUrl));
965                 SetProperty(ImageView.Property.IMAGE, new PropertyValue(temp));
966                 return;
967             }
968
969             if (_border == null)
970             {
971                 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
972             }
973             else
974             {
975                 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
976                 temp.Insert(NpatchImageVisualProperty.Border, new PropertyValue(_border));
977             }
978
979             temp.Insert(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue(_synchronosLoading));
980
981             if (value != null)
982             {
983                 temp.Insert(key, value);
984             }
985
986             UpdateImageMap(temp);
987
988             temp.Dispose();
989             temp = null;
990         }
991
992
993         private void OnResourceLoaded(IntPtr view)
994         {
995             ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
996             e.Status = (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
997
998             if (_resourceLoadedEventHandler != null)
999             {
1000                 _resourceLoadedEventHandler(this, e);
1001             }
1002         }
1003
1004         /// <summary>
1005         /// Event arguments of resource ready.
1006         /// </summary>
1007         /// <since_tizen> 3 </since_tizen>
1008         public class ResourceReadyEventArgs : EventArgs
1009         {
1010             private View _view;
1011
1012             /// <summary>
1013             /// The view whose resource is ready.
1014             /// </summary>
1015             /// <since_tizen> 3 </since_tizen>
1016             public View View
1017             {
1018                 get
1019                 {
1020                     return _view;
1021                 }
1022                 set
1023                 {
1024                     _view = value;
1025                 }
1026             }
1027         }
1028
1029         internal class ResourceLoadedEventArgs : EventArgs
1030         {
1031             private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1032             public ResourceLoadingStatusType Status
1033             {
1034                 get
1035                 {
1036                     return status;
1037                 }
1038                 set
1039                 {
1040                     status = value;
1041                 }
1042             }
1043         }
1044
1045         internal new class Property
1046         {
1047             internal static readonly int IMAGE = Interop.ImageView.ImageView_Property_IMAGE_get();
1048             internal static readonly int PRE_MULTIPLIED_ALPHA = Interop.ImageView.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
1049             internal static readonly int PIXEL_AREA = Interop.ImageView.ImageView_Property_PIXEL_AREA_get();
1050             internal static readonly int ACTION_RELOAD = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_RELOAD_get();
1051             internal static readonly int ACTION_PLAY = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_PLAY_get();
1052             internal static readonly int ACTION_PAUSE = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_PAUSE_get();
1053             internal static readonly int ACTION_STOP = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_STOP_get();
1054         }
1055
1056         private enum ImageType
1057         {
1058             /// <summary>
1059             /// For Normal Image.
1060             /// </summary>
1061             Normal = 0,
1062
1063             /// <summary>
1064             /// For normal image, with synchronous loading and orientation correction property
1065             /// </summary>
1066             Specific = 1,
1067
1068             /// <summary>
1069             /// For nine-patch image
1070             /// </summary>
1071             Npatch = 2,
1072         }
1073     }
1074 }