[NUI] Add EnvironmentVariable interface (internal API) (#533)
[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("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                 if (imageView.IsCreateByXaml && url.Contains("*Resource*"))
41                 {
42                     string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
43                     url = url.Replace("*Resource*", resource);
44                 }
45                 imageView._url = url;
46                 imageView.UpdateImage();
47             }
48         },
49         defaultValueCreator:(bindable) =>
50         {
51             var imageView = (ImageView)bindable;
52             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(out imageView._url);
53             return imageView._url;
54         });
55         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
56         [EditorBrowsable(EditorBrowsableState.Never)]
57         public static readonly BindableProperty ImageProperty = BindableProperty.Create("Image", typeof(PropertyMap), typeof(ImageView), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
58         {
59             var imageView = (ImageView)bindable;
60             if (newValue != null)
61             {
62                 PropertyMap map = (PropertyMap)newValue;
63                 if (imageView.IsCreateByXaml)
64                 {
65                     string url = "", alphaMaskURL="", auxiliaryImageURL = "";
66                     string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
67                     PropertyValue urlValue = map.Find(NDalic.IMAGE_VISUAL_URL);
68                     bool ret = false;
69                     if (urlValue != null) ret = urlValue.Get(out url);
70                     PropertyMap mmap = new PropertyMap();
71                     if (ret && url.Contains("*Resource*"))
72                     {
73                         url = url.Replace("*Resource*", resource);
74                         mmap.Insert(NDalic.IMAGE_VISUAL_URL, new PropertyValue(url));
75                     }
76
77                     ret = false;
78                     PropertyValue alphaMaskUrlValue = map.Find(NDalic.IMAGE_VISUAL_ALPHA_MASK_URL);
79                     if (alphaMaskUrlValue != null) ret = alphaMaskUrlValue.Get(out alphaMaskURL);
80                     if (ret && alphaMaskURL.Contains("*Resource*"))
81                     {
82                         alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource);
83                         mmap.Insert(NDalic.IMAGE_VISUAL_URL, new PropertyValue(alphaMaskURL));
84                     }
85
86                     ret = false;
87                     PropertyValue auxiliaryImageURLValue  = map.Find(NDalic.IMAGE_VISUAL_AUXILIARY_IMAGE_URL);
88                     if (auxiliaryImageURLValue != null) ret = auxiliaryImageURLValue.Get(out auxiliaryImageURL);
89                     if (ret && auxiliaryImageURL.Contains("*Resource*"))
90                     {
91                         auxiliaryImageURL = auxiliaryImageURL.Replace("*Resource*", resource);
92                         mmap.Insert(NDalic.IMAGE_VISUAL_AUXILIARY_IMAGE_URL, new PropertyValue(auxiliaryImageURL));
93                     }
94
95                     map.Merge(mmap);
96                 }
97                 if (imageView._border == null)
98                 {
99                     Tizen.NUI.Object.SetProperty(imageView.swigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
100                 }
101             }
102         },
103         defaultValueCreator:(bindable) =>
104         {
105             var imageView = (ImageView)bindable;
106             if (imageView._border == null)
107             {
108                 PropertyMap temp = new PropertyMap();
109                 Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(temp);
110                 return temp;
111             }
112             else
113             {
114                 return null;
115             }
116         });
117         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
118         [EditorBrowsable(EditorBrowsableState.Never)]
119         public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create("PreMultipliedAlpha", typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
120         {
121             var imageView = (ImageView)bindable;
122             if (newValue != null)
123             {
124                 Tizen.NUI.Object.SetProperty(imageView.swigCPtr, ImageView.Property.PRE_MULTIPLIED_ALPHA, new Tizen.NUI.PropertyValue((bool)newValue));
125             }
126         },
127         defaultValueCreator:(bindable) =>
128         {
129             var imageView = (ImageView)bindable;
130             bool temp = false;
131             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.PRE_MULTIPLIED_ALPHA).Get(out temp);
132             return temp;
133         });
134         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
135         [EditorBrowsable(EditorBrowsableState.Never)]
136         public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create("PixelArea", typeof(RelativeVector4), typeof(ImageView), new RelativeVector4(0,0,0,0), propertyChanged: (bindable, oldValue, newValue) =>
137         {
138             var imageView = (ImageView)bindable;
139             if (newValue != null)
140             {
141                 Tizen.NUI.Object.SetProperty(imageView.swigCPtr, ImageView.Property.PIXEL_AREA, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
142             }
143         },
144         defaultValueCreator:(bindable) =>
145         {
146             var imageView = (ImageView)bindable;
147             Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
148             Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.PIXEL_AREA).Get(temp);
149             RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
150             return relativeTemp;
151         });
152         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
153         [EditorBrowsable(EditorBrowsableState.Never)]
154         public static readonly BindableProperty BorderProperty = BindableProperty.Create("Border", typeof(Rectangle), typeof(ImageView), new Rectangle(0,0,0,0), propertyChanged: (bindable, oldValue, newValue) =>
155         {
156             var imageView = (ImageView)bindable;
157             if (newValue != null)
158             {
159                 imageView._border = (Rectangle)newValue;
160                 imageView.UpdateImage();
161             }
162         },
163         defaultValueCreator:(bindable) =>
164         {
165             var imageView = (ImageView)bindable;
166             return imageView._border;
167         });
168         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
169         [EditorBrowsable(EditorBrowsableState.Never)]
170         public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create("BorderOnly", typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
171         {
172             var imageView = (ImageView)bindable;
173             if (newValue != null)
174             {
175                 imageView._borderOnly = (bool)newValue;
176                 imageView.UpdateImage();
177             }
178         },
179         defaultValueCreator:(bindable) =>
180         {
181             var imageView = (ImageView)bindable;
182             return imageView._borderOnly ?? false;
183         });
184         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
185         [EditorBrowsable(EditorBrowsableState.Never)]
186         public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create("SynchronosLoading", typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
187         {
188             var imageView = (ImageView)bindable;
189             if (newValue != null)
190             {
191                 imageView._synchronousLoading = (bool)newValue;
192                 imageView.UpdateImage();
193             }
194         },
195         defaultValueCreator:(bindable) =>
196         {
197             var imageView = (ImageView)bindable;
198             return imageView._synchronousLoading ?? false;
199         });
200         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
201         [EditorBrowsable(EditorBrowsableState.Never)]
202         public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create("OrientationCorrection", typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
203         {
204             var imageView = (ImageView)bindable;
205             if (newValue != null)
206             {
207                 imageView._orientationCorrection = (bool)newValue;
208                 imageView.UpdateImage();
209             }
210         },
211         defaultValueCreator:(bindable) =>
212         {
213             var imageView = (ImageView)bindable;
214             return imageView._orientationCorrection ?? false;
215         });
216
217         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
218
219         internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.ImageView_SWIGUpcast(cPtr), cMemoryOwn)
220         {
221             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
222         }
223
224         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImageView obj)
225         {
226             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
227         }
228
229
230         /// <summary>
231         /// Event arguments of resource ready.
232         /// </summary>
233         /// <since_tizen> 3 </since_tizen>
234         public class ResourceReadyEventArgs : EventArgs
235         {
236             private View _view;
237
238             /// <summary>
239             /// The view whose resource is ready.
240             /// </summary>
241             /// <since_tizen> 3 </since_tizen>
242             public View View
243             {
244                 get
245                 {
246                     return _view;
247                 }
248                 set
249                 {
250                     _view = value;
251                 }
252             }
253         }
254
255         private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
256         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
257         private delegate void ResourceReadyEventCallbackType(IntPtr data);
258         private ResourceReadyEventCallbackType _resourceReadyEventCallback;
259
260         /// <summary>
261         /// An event for ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
262         /// This signal is emitted after all resources required by a control are loaded and ready.<br />
263         /// Most resources are only loaded when the control is placed on the stage.<br />
264         /// </summary>
265         /// <since_tizen> 3 </since_tizen>
266         public event EventHandler<ResourceReadyEventArgs> ResourceReady
267         {
268             add
269             {
270                 if (_resourceReadyEventHandler == null)
271                 {
272                     _resourceReadyEventCallback = OnResourceReady;
273                     ResourceReadySignal(this).Connect(_resourceReadyEventCallback);
274                 }
275
276                 _resourceReadyEventHandler += value;
277             }
278
279             remove
280             {
281                 _resourceReadyEventHandler -= value;
282
283                 if (_resourceReadyEventHandler == null && ResourceReadySignal(this).Empty() == false)
284                 {
285                     ResourceReadySignal(this).Disconnect(_resourceReadyEventCallback);
286                 }
287             }
288         }
289
290         // Callback for View ResourceReady signal
291         private void OnResourceReady(IntPtr data)
292         {
293             ResourceReadyEventArgs e = new ResourceReadyEventArgs();
294             if (data != null)
295             {
296                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
297             }
298
299             if (_resourceReadyEventHandler != null)
300             {
301                 _resourceReadyEventHandler(this, e);
302             }
303         }
304
305         /// <summary>
306         /// you can override it to clean-up your own resources.
307         /// </summary>
308         /// <param name="type">DisposeTypes</param>
309         /// <since_tizen> 3 </since_tizen>
310         protected override void Dispose(DisposeTypes type)
311         {
312             if (disposed)
313             {
314                 return;
315             }
316
317             if (type == DisposeTypes.Explicit)
318             {
319                 //Called by User
320                 //Release your own managed resources here.
321                 //You should release all of your own disposable objects here.
322                 _border?.Dispose();
323                 _border = null;
324                 _nPatchMap?.Dispose();
325                 _nPatchMap = null;
326             }
327
328             //Release your own unmanaged resources here.
329             //You should not access any managed member here except static instance.
330             //because the execution order of Finalizes is non-deterministic.
331
332             if (swigCPtr.Handle != global::System.IntPtr.Zero)
333             {
334                 if (swigCMemOwn)
335                 {
336                     swigCMemOwn = false;
337                     NDalicPINVOKE.delete_ImageView(swigCPtr);
338                 }
339                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
340             }
341
342             base.Dispose(type);
343         }
344
345         internal new class Property
346         {
347             internal static readonly int RESOURCE_URL = NDalicPINVOKE.ImageView_Property_RESOURCE_URL_get();
348             internal static readonly int IMAGE = NDalicPINVOKE.ImageView_Property_IMAGE_get();
349             internal static readonly int PRE_MULTIPLIED_ALPHA = NDalicPINVOKE.ImageView_Property_PRE_MULTIPLIED_ALPHA_get();
350             internal static readonly int PIXEL_AREA = NDalicPINVOKE.ImageView_Property_PIXEL_AREA_get();
351             internal static readonly int ACTION_RELOAD = NDalicManualPINVOKE.ImageView_IMAGE_VISUAL_ACTION_RELOAD_get();
352             internal static readonly int ACTION_PLAY = NDalicManualPINVOKE.ImageView_IMAGE_VISUAL_ACTION_PLAY_get();
353             internal static readonly int ACTION_PAUSE = NDalicManualPINVOKE.ImageView_IMAGE_VISUAL_ACTION_PAUSE_get();
354             internal static readonly int ACTION_STOP = NDalicManualPINVOKE.ImageView_IMAGE_VISUAL_ACTION_STOP_get();
355         }
356
357         /// <summary>
358         /// Creates an initialized ImageView.
359         /// </summary>
360         /// <since_tizen> 3 </since_tizen>
361         public ImageView() : this(NDalicPINVOKE.ImageView_New__SWIG_0(), true)
362         {
363             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364         }
365
366         /// <summary>
367         /// Creates an initialized ImageView from a URL to an image resource.<br />
368         /// If the string is empty, ImageView will not display anything.<br />
369         /// </summary>
370         /// <param name="url">The URL of the image resource to display.</param>
371         /// <since_tizen> 3 </since_tizen>
372         public ImageView(string url) : this(NDalicPINVOKE.ImageView_New__SWIG_2(url), true)
373         {
374             _url = url;
375             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376
377         }
378         internal ImageView(string url, Uint16Pair size) : this(NDalicPINVOKE.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true)
379         {
380             _url = url;
381             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
382
383         }
384
385         /// <summary>
386         /// Downcasts a handle to imageView handle.
387         /// </summary>
388         /// Please do not use! this will be deprecated!
389         /// Instead please use as keyword.
390         /// <since_tizen> 3 </since_tizen>
391         [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
392             "Like: " +
393             "BaseHandle handle = new ImageView(imagePath); " +
394             "ImageView image = handle as ImageView")]
395         [EditorBrowsable(EditorBrowsableState.Never)]
396         public static ImageView DownCast(BaseHandle handle)
397         {
398             ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
399             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400             return ret;
401         }
402
403         /// <summary>
404         /// Sets this ImageView from the given URL.<br />
405         /// If the URL is empty, ImageView will not display anything.<br />
406         /// </summary>
407         /// <param name="url">The URL to the image resource to display.</param>
408         /// <since_tizen> 3 </since_tizen>
409         public void SetImage(string url)
410         {
411             _url = url;
412             NDalicPINVOKE.ImageView_SetImage__SWIG_1(swigCPtr, url);
413             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414         }
415         internal void SetImage(string url, Uint16Pair size)
416         {
417             _url = url;
418             NDalicPINVOKE.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size));
419             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
420         }
421
422         internal ViewResourceReadySignal ResourceReadySignal(View view)
423         {
424             ViewResourceReadySignal ret = new ViewResourceReadySignal(NDalicPINVOKE.ResourceReadySignal(View.getCPtr(view)), false);
425             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
426             return ret;
427         }
428
429         /// <summary>
430         /// Queries if all resources required by a control are loaded and ready.<br />
431         /// Most resources are only loaded when the control is placed on the stage.<br />
432         /// True if the resources are loaded and ready, false otherwise.<br />
433         /// </summary>
434         /// <since_tizen> 3 </since_tizen>
435         public new bool IsResourceReady()
436         {
437             bool ret = NDalicPINVOKE.IsResourceReady(swigCPtr);
438             if (NDalicPINVOKE.SWIGPendingException.Pending)
439                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
440             return ret;
441         }
442
443         /// <summary>
444         /// Forcefully reloads the image. All the visuals using this image will reload to the latest image.
445         /// </summary>
446         /// <since_tizen> 5 </since_tizen>        
447         public void Reload()
448         {
449             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_RELOAD, new PropertyValue(0));
450         }
451
452         /// <summary>
453         /// Plays the animated GIF. This is also the default playback mode.
454         /// </summary>
455         /// <since_tizen> 5 </since_tizen>
456         public void Play()
457         {
458             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_PLAY, new PropertyValue(0));
459         }
460
461         /// <summary>
462         /// Pauses the animated GIF.
463         /// </summary>
464         /// <since_tizen> 5 </since_tizen>
465         public void Pause()
466         {
467             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_PAUSE, new PropertyValue(0));
468         }
469
470         /// <summary>
471         /// Stops the animated GIF.
472         /// </summary>
473         /// <since_tizen> 5 </since_tizen>
474         public void Stop()
475         {
476             this.DoAction(ImageView.Property.IMAGE, Property.ACTION_STOP, new PropertyValue(0));
477         }
478
479         /// <summary>
480         /// ImageView ResourceUrl, type string.
481         /// </summary>
482         /// <since_tizen> 3 </since_tizen>
483         public string ResourceUrl
484         {
485             get
486             {
487                 return (string)GetValue(ResourceUrlProperty);
488             }
489             set
490             {
491                 SetValue(ResourceUrlProperty, value);
492                 NotifyPropertyChanged();
493             }
494         }
495
496         /// <summary>
497         /// This will be deprecated, please use Image instead. <br />
498         /// ImageView ImageMap, type PropertyMap: string if it is a URL, map otherwise.
499         /// </summary>
500         /// <since_tizen> 3 </since_tizen>
501         [Obsolete("Please do not use! This will be deprecated! Please use Image property instead!")]
502         [EditorBrowsable(EditorBrowsableState.Never)]
503         public PropertyMap ImageMap
504         {
505             get
506             {
507                 if (_border == null)
508                 {
509                     PropertyMap temp = new PropertyMap();
510                     GetProperty(ImageView.Property.IMAGE).Get(temp);
511                     return temp;
512                 }
513                 else
514                 {
515                     return null;
516                 }
517             }
518             set
519             {
520                 if (_border == null)
521                 {
522                     if (_url != null) { value.Add("url", new PropertyValue(_url)); }
523                     SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value));
524                     NotifyPropertyChanged();
525                 }
526             }
527         }
528
529         /// <summary>
530         /// ImageView Image, type PropertyMap
531         /// </summary>
532         /// <since_tizen> 4 </since_tizen>
533         public PropertyMap Image
534         {
535             get
536             {
537                 if (_border == null)
538                 {
539                     return (PropertyMap)GetValue(ImageProperty);
540                 }
541                 else
542                 {
543                     return null;
544                 }
545             }
546             set
547             {
548                 if (_border == null)
549                 {
550                     SetValue(ImageProperty, value);
551                     NotifyPropertyChanged();
552                 }
553             }
554         }
555
556         /// <summary>
557         /// ImageView PreMultipliedAlpha, type Boolean.<br />
558         /// Image must be initialized.<br />
559         /// </summary>
560         /// <since_tizen> 3 </since_tizen>
561         public bool PreMultipliedAlpha
562         {
563             get
564             {
565                 return (bool)GetValue(PreMultipliedAlphaProperty);
566             }
567             set
568             {
569                 SetValue(PreMultipliedAlphaProperty, value);
570                 NotifyPropertyChanged();
571             }
572         }
573
574         /// <summary>
575         /// ImageView PixelArea, type Vector4 (Animatable property).<br />
576         /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br />
577         /// </summary>
578         /// <since_tizen> 3 </since_tizen>
579         public RelativeVector4 PixelArea
580         {
581             get
582             {
583                 return (RelativeVector4)GetValue(PixelAreaProperty);
584             }
585             set
586             {
587                 SetValue(PixelAreaProperty, value);
588                 NotifyPropertyChanged();
589             }
590         }
591
592         /// <summary>
593         /// The border of the image in the order: left, right, bottom, top.<br />
594         /// If set, ImageMap will be ignored.<br />
595         /// For N-Patch images only.<br />
596         /// Optional.
597         /// </summary>
598         /// <since_tizen> 3 </since_tizen>
599         public Rectangle Border
600         {
601             get
602             {
603                 return (Rectangle)GetValue(BorderProperty);
604             }
605             set
606             {
607                 SetValue(BorderProperty, value);
608                 NotifyPropertyChanged();
609             }
610         }
611
612         /// <summary>
613         /// Gets or sets whether to draw the borders only (if true).<br />
614         /// If not specified, the default is false.<br />
615         /// For N-Patch images only.<br />
616         /// Optional.
617         /// </summary>
618         /// <since_tizen> 3 </since_tizen>
619         public bool BorderOnly
620         {
621             get
622             {
623                 return (bool)GetValue(BorderOnlyProperty);
624             }
625             set
626             {
627                 SetValue(BorderOnlyProperty, value);
628                 NotifyPropertyChanged();
629             }
630         }
631
632         /// <summary>
633         /// Gets or sets whether to synchronos loading the resourceurl of image.<br />
634         /// </summary>
635         /// <since_tizen> 3 </since_tizen>
636         public bool SynchronosLoading
637         {
638             get
639             {
640                 return (bool)GetValue(SynchronosLoadingProperty);
641             }
642             set
643             {
644                 SetValue(SynchronosLoadingProperty, value);
645                 NotifyPropertyChanged();
646             }
647         }
648
649         /// <summary>
650         /// Gets or sets whether to automatically correct the orientation of an image.<br />
651         /// </summary>
652         /// <since_tizen> 5 </since_tizen>
653         public bool OrientationCorrection
654         {
655             get
656             {
657                 return (bool)GetValue(OrientationCorrectionProperty);
658             }
659             set
660             {
661                 SetValue(OrientationCorrectionProperty, value);
662                 NotifyPropertyChanged();
663             }
664         }
665
666
667         /// <summary>
668         /// Gets the loading state of the visual resource.
669         /// </summary>
670         /// <since_tizen> 5 </since_tizen>
671         public ImageView.LoadingStatusType LoadingStatus
672         {
673             get
674             {
675                 return (ImageView.LoadingStatusType)NDalicManualPINVOKE.View_GetVisualResourceStatus(swigCPtr, (int)Property.IMAGE);
676             }
677         }
678
679         /// <summary>
680         /// Enumeration for LoadingStatus of image.
681         /// </summary>
682         /// <since_tizen> 5 </since_tizen>
683         public enum LoadingStatusType
684         {
685             /// <summary>
686             /// Loading preparing status.
687             /// </summary>
688             /// <since_tizen> 5 </since_tizen>
689             Preparing,
690             /// <summary>
691             /// Loading ready status.
692             /// </summary>
693             /// <since_tizen> 5 </since_tizen>
694             Ready,
695             /// <summary>
696             /// Loading failed status.
697             /// </summary>
698             /// <since_tizen> 5 </since_tizen>
699             Failed
700         }
701
702
703         private void UpdateImage()
704         {
705             if (_url != null)
706             {
707                 if (_border != null)
708                 { // for nine-patch image
709                     _nPatchMap = new PropertyMap();
710                     _nPatchMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
711                     _nPatchMap.Add(NpatchImageVisualProperty.URL, new PropertyValue(_url));
712                     _nPatchMap.Add(NpatchImageVisualProperty.Border, new PropertyValue(_border));
713                     if (_borderOnly != null) { _nPatchMap.Add(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)_borderOnly)); }
714                     if (_synchronousLoading != null) { _nPatchMap.Add(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading)); }
715                     if (_orientationCorrection != null) { _nPatchMap.Add(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)_orientationCorrection)); }
716                     SetProperty(ImageView.Property.IMAGE, new PropertyValue(_nPatchMap));
717                 }
718                 else if (_synchronousLoading != null || _orientationCorrection != null)
719                 { // for normal image, with synchronous loading property
720                     PropertyMap imageMap = new PropertyMap();
721                     imageMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
722                     imageMap.Add(ImageVisualProperty.URL, new PropertyValue(_url));
723                     if (_synchronousLoading != null) { imageMap.Add(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading)); }
724                     if (_orientationCorrection != null) { imageMap.Add(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)_orientationCorrection)); }
725                     SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap));
726                 }
727                 else
728                 { // just for normal image
729                     SetProperty(ImageView.Property.IMAGE, new PropertyValue(_url));
730                 }
731             }
732         }
733
734         private Rectangle _border = null;
735         private PropertyMap _nPatchMap = null;
736         private bool? _synchronousLoading = null;
737         private bool? _borderOnly = null;
738         private string _url = null;
739         private bool? _orientationCorrection = null;
740
741
742         internal class ResourceLoadedEventArgs : EventArgs
743         {
744             private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
745             public ResourceLoadingStatusType Status
746             {
747                 get
748                 {
749                     return status;
750                 }
751                 set
752                 {
753                     status = value;
754                 }
755             }
756         }
757
758         private EventHandler<ResourceLoadedEventArgs> _resourceLoadedEventHandler;
759         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
760         private delegate void _resourceLoadedCallbackType(IntPtr view);
761         private _resourceLoadedCallbackType _resourceLoadedCallback;
762
763         internal event EventHandler<ResourceLoadedEventArgs> ResourceLoaded
764         {
765             add
766             {
767                 if (_resourceLoadedEventHandler == null)
768                 {
769                     _resourceLoadedCallback = OnResourceLoaded;
770                     this.ResourceReadySignal(this).Connect(_resourceLoadedCallback);
771                 }
772
773                 _resourceLoadedEventHandler += value;
774             }
775             remove
776             {
777                 _resourceLoadedEventHandler -= value;
778
779                 if (_resourceLoadedEventHandler == null && this.ResourceReadySignal(this).Empty() == false)
780                 {
781                     this.ResourceReadySignal(this).Disconnect(_resourceLoadedCallback);
782                 }
783             }
784         }
785
786         private void OnResourceLoaded(IntPtr view)
787         {
788             ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
789             e.Status = (ResourceLoadingStatusType)NDalicManualPINVOKE.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
790
791             if (_resourceLoadedEventHandler != null)
792             {
793                 _resourceLoadedEventHandler(this, e);
794             }
795         }
796
797         internal ResourceLoadingStatusType GetResourceStatus()
798         {
799             return (ResourceLoadingStatusType)NDalicManualPINVOKE.View_GetVisualResourceStatus(this.swigCPtr, Property.IMAGE);
800         }
801
802
803     }
804
805 }