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