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