[NUI] Fix ImageView bug (#917)
[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             Interop.ImageView.ImageView_SetImage__SWIG_1(swigCPtr, url);
586             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
587
588             ResourceUrl = url;
589         }
590
591         /// <summary>
592         /// Queries if all resources required by a control are loaded and ready.<br />
593         /// Most resources are only loaded when the control is placed on the stage.<br />
594         /// True if the resources are loaded and ready, false otherwise.<br />
595         /// </summary>
596         /// <since_tizen> 3 </since_tizen>
597         public new bool IsResourceReady()
598         {
599             bool ret = Interop.View.IsResourceReady(swigCPtr);
600             if (NDalicPINVOKE.SWIGPendingException.Pending)
601                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
602             return ret;
603         }
604
605         /// <summary>
606         /// Forcefully reloads the image. All the visuals using this image will reload to the latest image.
607         /// </summary>
608         /// <since_tizen> 5 </since_tizen>
609         public void Reload()
610         {
611             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_RELOAD, new PropertyValue(0));
612         }
613
614         /// <summary>
615         /// Plays the animated GIF. This is also the default playback mode.
616         /// </summary>
617         /// <since_tizen> 5 </since_tizen>
618         public void Play()
619         {
620             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_PLAY, new PropertyValue(0));
621         }
622
623         /// <summary>
624         /// Pauses the animated GIF.
625         /// </summary>
626         /// <since_tizen> 5 </since_tizen>
627         public void Pause()
628         {
629             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_PAUSE, new PropertyValue(0));
630         }
631
632         /// <summary>
633         /// Stops the animated GIF.
634         /// </summary>
635         /// <since_tizen> 5 </since_tizen>
636         public void Stop()
637         {
638             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_STOP, new PropertyValue(0));
639         }
640
641         /// <summary>
642         /// Gets or sets the URL of the alpha mask.<br />
643         /// Optional.
644         /// </summary>
645         /// <since_tizen> 6</since_tizen>
646         [EditorBrowsable(EditorBrowsableState.Never)]
647         public string AlphaMaskURL
648         {
649             get
650             {
651                 string ret = "";
652                 PropertyMap imageMap = new PropertyMap();
653                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
654                 imageMap?.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out ret);
655
656                 return ret;
657             }
658             set
659             {
660                 if (value == null)
661                 {
662                     value = "";
663                 }
664
665                 UpdateImage(ImageVisualProperty.AlphaMaskURL, new PropertyValue(value));
666             }
667         }
668
669
670         /// <summary>
671         ///  Whether to crop image to mask or scale mask to fit image.
672         /// </summary>
673         /// <since_tizen> 6 </since_tizen>
674         [EditorBrowsable(EditorBrowsableState.Never)]
675         public bool CropToMask
676         {
677             get
678             {
679                 bool ret = false;
680                 PropertyMap imageMap = new PropertyMap();
681                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
682                 imageMap?.Find(ImageVisualProperty.CropToMask)?.Get(out ret);
683
684                 return ret;
685             }
686             set
687             {
688                 UpdateImage(ImageVisualProperty.CropToMask, new PropertyValue(value));
689             }
690         }
691
692
693         /// <summary>
694         /// Gets or sets fitting options used when resizing images to fit the desired dimensions.<br />
695         /// If not supplied, the default is FittingModeType.ShrinkToFit.<br />
696         /// For normal quad images only.<br />
697         /// Optional.
698         /// </summary>
699         /// <since_tizen> 6 </since_tizen>
700         [EditorBrowsable(EditorBrowsableState.Never)]
701         public FittingModeType FittingMode
702         {
703             get
704             {
705                 int ret = (int)FittingModeType.ShrinkToFit;
706                 PropertyMap imageMap = new PropertyMap();
707                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
708                 imageMap?.Find(ImageVisualProperty.FittingMode)?.Get(out ret);
709
710                 return (FittingModeType)ret;
711             }
712             set
713             {
714                 UpdateImage(ImageVisualProperty.CropToMask, new PropertyValue((int)value));
715             }
716         }
717
718
719
720         /// <summary>
721         /// Gets or sets the desired image width.<br />
722         /// If not specified, the actual image width is used.<br />
723         /// For normal quad images only.<br />
724         /// Optional.
725         /// </summary>
726         /// <since_tizen> 6 </since_tizen>
727         [EditorBrowsable(EditorBrowsableState.Never)]
728         public int DesiredWidth
729         {
730             get
731             {
732                 int ret = -1;
733                 PropertyMap imageMap = new PropertyMap();
734                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
735                 imageMap?.Find(ImageVisualProperty.DesiredWidth)?.Get(out ret);
736
737                 return ret;
738             }
739             set
740             {
741                 UpdateImage(ImageVisualProperty.DesiredWidth, new PropertyValue(value));
742             }
743         }
744
745         /// <summary>
746         /// Gets or sets the desired image height.<br />
747         /// If not specified, the actual image height is used.<br />
748         /// For normal quad images only.<br />
749         /// Optional.
750         /// </summary>
751         /// <since_tizen> 6 </since_tizen>
752         [EditorBrowsable(EditorBrowsableState.Never)]
753         public int DesiredHeight
754         {
755             get
756             {
757                 int ret = -1;
758                 PropertyMap imageMap = new PropertyMap();
759                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
760                 imageMap?.Find(ImageVisualProperty.DesiredHeight)?.Get(out ret);
761
762                 return ret;
763             }
764             set
765             {
766                 UpdateImage(ImageVisualProperty.DesiredHeight, new PropertyValue(value));
767             }
768         }
769
770
771         /// <summary>
772         /// Gets or sets the wrap mode for the u coordinate.<br />
773         /// It decides how the texture should be sampled when the u coordinate exceeds the range of 0.0 to 1.0.<br />
774         /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
775         /// For normal quad images only.<br />
776         /// Optional.
777         /// </summary>
778         /// <since_tizen> 6 </since_tizen>
779         [EditorBrowsable(EditorBrowsableState.Never)]
780         public WrapModeType WrapModeU
781         {
782             get
783             {
784                 int ret = (int)WrapModeType.Default;
785                 PropertyMap imageMap = new PropertyMap();
786                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
787                 imageMap?.Find(ImageVisualProperty.WrapModeU)?.Get(out ret);
788
789                 return (WrapModeType)ret;
790             }
791             set
792             {
793                 UpdateImage(ImageVisualProperty.WrapModeU, new PropertyValue((int)value));
794             }
795         }
796
797         /// <summary>
798         /// Gets or sets the wrap mode for the v coordinate.<br />
799         /// It decides how the texture should be sampled when the v coordinate exceeds the range of 0.0 to 1.0.<br />
800         /// 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 />
801         /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
802         /// For normal quad images only.
803         /// Optional.
804         /// </summary>
805         /// <since_tizen> 6 </since_tizen>
806         [EditorBrowsable(EditorBrowsableState.Never)]
807         public WrapModeType WrapModeV
808         {
809             get
810             {
811                 int ret = (int)WrapModeType.Default;
812                 PropertyMap imageMap = new PropertyMap();
813                 Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
814                 imageMap?.Find(ImageVisualProperty.WrapModeV)?.Get(out ret);
815
816                 return (WrapModeType)ret;
817             }
818             set
819             {
820                 UpdateImage(ImageVisualProperty.WrapModeV, new PropertyValue((int)value));
821             }
822         }
823
824
825         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImageView obj)
826         {
827             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
828         }
829
830         internal void SetImage(string url, Uint16Pair size)
831         {
832             Interop.ImageView.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
833             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
834                         
835             ResourceUrl = url;
836         }
837
838         internal ViewResourceReadySignal ResourceReadySignal(View view)
839         {
840             ViewResourceReadySignal ret = new ViewResourceReadySignal(Interop.View.ResourceReadySignal(View.getCPtr(view)), false);
841             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
842             return ret;
843         }
844
845         internal ResourceLoadingStatusType GetResourceStatus()
846         {
847             return (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
848         }
849
850         /// <summary>
851         /// you can override it to clean-up your own resources.
852         /// </summary>
853         /// <param name="type">DisposeTypes</param>
854         /// <since_tizen> 3 </since_tizen>
855         protected override void Dispose(DisposeTypes type)
856         {
857             if (disposed)
858             {
859                 return;
860             }
861
862             if (type == DisposeTypes.Explicit)
863             {
864                 //Called by User
865                 //Release your own managed resources here.
866                 //You should release all of your own disposable objects here.
867                 _border?.Dispose();
868                 _border = null;
869             }
870
871             //Release your own unmanaged resources here.
872             //You should not access any managed member here except static instance.
873             //because the execution order of Finalizes is non-deterministic.
874
875             if (swigCPtr.Handle != global::System.IntPtr.Zero)
876             {
877                 if (swigCMemOwn)
878                 {
879                     swigCMemOwn = false;
880                     Interop.ImageView.delete_ImageView(swigCPtr);
881                 }
882                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
883             }
884
885             base.Dispose(type);
886         }
887
888         // Callback for View ResourceReady signal
889         private void OnResourceReady(IntPtr data)
890         {
891             ResourceReadyEventArgs e = new ResourceReadyEventArgs();
892             if (data != null)
893             {
894                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
895             }
896
897             if (_resourceReadyEventHandler != null)
898             {
899                 _resourceReadyEventHandler(this, e);
900             }
901         }
902
903         private void UpdateImageMap(PropertyMap fromMap)
904         {
905             PropertyMap imageMap = new PropertyMap();
906             Tizen.NUI.Object.GetProperty(swigCPtr, ImageView.Property.IMAGE).Get(imageMap);
907             imageMap.Merge(fromMap);
908                         
909             SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
910         }
911                 
912         private void UpdateImage(int key, PropertyValue value)
913         {
914             PropertyMap temp = new PropertyMap();
915
916             if (_resourceUrl == "")
917             {
918                 temp.Insert(ImageVisualProperty.URL, new PropertyValue(_resourceUrl));
919                 SetProperty(ImageView.Property.IMAGE, new PropertyValue(temp));
920                 return;
921             }
922
923             if (_border == null)
924             {
925                 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
926             }
927             else
928             {
929                 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
930                 temp.Insert(NpatchImageVisualProperty.Border, new PropertyValue(_border));
931             }
932         
933             if (value != null)
934             {
935                 temp.Insert(key, value);
936             }
937
938             UpdateImageMap(temp);
939
940             temp.Dispose();
941             temp = null;
942         }
943
944
945         private void OnResourceLoaded(IntPtr view)
946         {
947             ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
948             e.Status = (ResourceLoadingStatusType)Interop.View.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
949
950             if (_resourceLoadedEventHandler != null)
951             {
952                 _resourceLoadedEventHandler(this, e);
953             }
954         }
955
956         /// <summary>
957         /// Event arguments of resource ready.
958         /// </summary>
959         /// <since_tizen> 3 </since_tizen>
960         public class ResourceReadyEventArgs : EventArgs
961         {
962             private View _view;
963
964             /// <summary>
965             /// The view whose resource is ready.
966             /// </summary>
967             /// <since_tizen> 3 </since_tizen>
968             public View View
969             {
970                 get
971                 {
972                     return _view;
973                 }
974                 set
975                 {
976                     _view = value;
977                 }
978             }
979         }
980
981         internal class ResourceLoadedEventArgs : EventArgs
982         {
983             private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
984             public ResourceLoadingStatusType Status
985             {
986                 get
987                 {
988                     return status;
989                 }
990                 set
991                 {
992                     status = value;
993                 }
994             }
995         }
996
997         internal new class Property
998         {
999             internal static readonly int RESOURCE_URL = Interop.ImageView.ImageView_Property_RESOURCE_URL_get();
1000             internal static readonly int IMAGE = Interop.ImageView.ImageView_Property_IMAGE_get();
1001             internal static readonly int PRE_MULTIPLIED_ALPHA = Interop.ImageView.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
1002             internal static readonly int PIXEL_AREA = Interop.ImageView.ImageView_Property_PIXEL_AREA_get();
1003             internal static readonly int ACTION_RELOAD = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_RELOAD_get();
1004             internal static readonly int ACTION_PLAY = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_PLAY_get();
1005             internal static readonly int ACTION_PAUSE = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_PAUSE_get();
1006             internal static readonly int ACTION_STOP = Interop.ImageView.ImageView_IMAGE_VISUAL_ACTION_STOP_get();
1007         }
1008
1009         private enum ImageType
1010         {
1011             /// <summary>
1012             /// For Normal Image.
1013             /// </summary>
1014             Normal = 0,
1015
1016             /// <summary>
1017             /// For normal image, with synchronous loading and orientation correction property
1018             /// </summary>
1019             Specific = 1,
1020
1021             /// <summary>
1022             /// For nine-patch image
1023             /// </summary>
1024             Npatch = 2,
1025         }
1026     }
1027 }