From 95bf5da51c4c4d146c69ed234f94ecab841469d2 Mon Sep 17 00:00:00 2001 From: huiyueun <35286162+huiyueun@users.noreply.github.com> Date: Wed, 5 Jun 2019 09:58:24 +0900 Subject: [PATCH] [NUI] fix GetSize() for multi window (#876) * Revert "[NUI] Add API for NUI Multi WIndow (#875)" This reverts commit 33a2741d99f17fa81da4f24b6faee256962980a0. * Add API for NUI Multi Window * fix typo after MultiWindow patch * [NUI] fix GetSize() for multi window * Fix ImageView crash issue Signed-off-by: huiyu.eun --- .../src/public/BaseComponents/ImageView.cs | 201 ++++++++++-------- src/Tizen.NUI/src/public/Window.cs | 3 +- 2 files changed, 116 insertions(+), 88 deletions(-) diff --git a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs index 6074ba7bb..60e6adaf3 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/ImageView.cs @@ -34,18 +34,21 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create(nameof(ImageView.ResourceUrl), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) => { var imageView = (ImageView)bindable; - string url = (string)newValue; - url = (url == null ? "" : url); - - imageView.UpdateImage(ImageVisualProperty.URL, new PropertyValue(url)); + if (newValue != null) + { + string url = (string)newValue; + imageView._url = url; + imageView.UpdateImage(); + } }, defaultValueCreator: (bindable) => { var imageView = (ImageView)bindable; - string ret = ""; - PropertyMap imageMap = (PropertyMap)imageView.GetValue(ImageProperty); - imageMap.Find(ImageVisualProperty.URL)?.Get(out ret); - return ret; + if(imageView._imageType == ImageType.Normal) + { + Tizen.NUI.Object.GetProperty(imageView.swigCPtr, ImageView.Property.IMAGE).Get(out imageView._url); + } + return imageView._url; }); /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -59,7 +62,8 @@ namespace Tizen.NUI.BaseComponents if (imageView._border == null) { - Tizen.NUI.Object.SetProperty(imageView.swigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map)); + imageView._image = map; + imageView.UpdateImage(); } } }, @@ -120,14 +124,10 @@ namespace Tizen.NUI.BaseComponents public static readonly BindableProperty BorderProperty = BindableProperty.Create("Border", typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) => { var imageView = (ImageView)bindable; - imageView._border = (Rectangle)newValue; if (newValue != null) { - imageView.UpdateImage(ImageVisualProperty.Border, new PropertyValue(imageView._border)); - } - else - { - imageView.UpdateImage(ImageVisualProperty.Border, new PropertyValue(new Rectangle(0,0,0,0))); + imageView._border = (Rectangle)newValue; + imageView.UpdateImage(); } }, defaultValueCreator: (bindable) => @@ -143,16 +143,14 @@ namespace Tizen.NUI.BaseComponents var imageView = (ImageView)bindable; if (newValue != null) { - imageView.UpdateImage(ImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue)); + imageView._borderOnly = (bool)newValue; + imageView.UpdateImage(); } }, defaultValueCreator: (bindable) => { var imageView = (ImageView)bindable; - bool ret = false; - PropertyMap imageMap = (PropertyMap)imageView.GetValue(ImageProperty); - imageMap.Find(ImageVisualProperty.BorderOnly)?.Get(out ret); - return ret; + return imageView._borderOnly ?? false; }); /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -162,16 +160,14 @@ namespace Tizen.NUI.BaseComponents var imageView = (ImageView)bindable; if (newValue != null) { - imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue)); + imageView._synchronousLoading = (bool)newValue; + imageView.UpdateImage(); } }, defaultValueCreator: (bindable) => { var imageView = (ImageView)bindable; - bool ret = false; - PropertyMap imageMap = (PropertyMap)imageView.GetValue(ImageProperty); - imageMap.Find(ImageVisualProperty.SynchronousLoading)?.Get(out ret); - return ret; + return imageView._synchronousLoading ?? false; }); /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. @@ -181,18 +177,14 @@ namespace Tizen.NUI.BaseComponents var imageView = (ImageView)bindable; if (newValue != null) { - imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue)); + imageView._orientationCorrection = (bool)newValue; + imageView.UpdateImage(); } }, defaultValueCreator: (bindable) => { var imageView = (ImageView)bindable; - - bool ret = false; - PropertyMap imageMap = (PropertyMap)imageView.GetValue(ImageProperty); - imageMap?.Find(ImageVisualProperty.OrientationCorrection)?.Get(out ret); - - return ret; + return imageView._orientationCorrection ?? false; }); private global::System.Runtime.InteropServices.HandleRef swigCPtr; @@ -202,6 +194,13 @@ namespace Tizen.NUI.BaseComponents private _resourceLoadedCallbackType _resourceLoadedCallback; private Rectangle _border; + private PropertyMap _nPatchMap; + private bool? _synchronousLoading; + private bool? _borderOnly; + private string _url; + private bool? _orientationCorrection; + private PropertyMap _image; + private ImageType _imageType; /// /// Creates an initialized ImageView. @@ -220,13 +219,13 @@ namespace Tizen.NUI.BaseComponents /// 3 public ImageView(string url) : this(Interop.ImageView.ImageView_New__SWIG_2(url), true) { - UpdateImage(ImageVisualProperty.URL, new PropertyValue(url)); + _url = url; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal ImageView(string url, Uint16Pair size) : this(Interop.ImageView.ImageView_New__SWIG_3(url, Uint16Pair.getCPtr(size)), true) { - UpdateImage(ImageVisualProperty.URL, new PropertyValue(url)); + _url = url; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } @@ -330,8 +329,10 @@ namespace Tizen.NUI.BaseComponents } set { - SetValue(ResourceUrlProperty, value); - NotifyPropertyChanged(); + _url = (value == null ? "" : value); + SetValue(ResourceUrlProperty, _url); + NotifyPropertyChanged(); + } } @@ -361,6 +362,7 @@ namespace Tizen.NUI.BaseComponents { if (_border == null) { + if (_url != null) { value.Add("url", new PropertyValue(_url)); } SetProperty(ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(value)); NotifyPropertyChanged(); } @@ -542,7 +544,9 @@ namespace Tizen.NUI.BaseComponents /// 3 public void SetImage(string url) { - UpdateImage(ImageVisualProperty.URL, new PropertyValue(url)); + _url = url; + Interop.ImageView.ImageView_SetImage__SWIG_1(swigCPtr, url); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// @@ -606,8 +610,7 @@ namespace Tizen.NUI.BaseComponents get { string ret = ""; - PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); - imageMap?.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out ret); + Image.Find(ImageVisualProperty.AlphaMaskURL)?.Get(out ret); return ret; } @@ -622,11 +625,10 @@ namespace Tizen.NUI.BaseComponents temp.Insert(ImageVisualProperty.AlphaMaskURL, new PropertyValue(value)); PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); - imageMap.Merge(temp); - - SetValue(ImageProperty, imageMap); - NotifyPropertyChanged(); + + SetValue(ImageProperty, imageMap); + NotifyPropertyChanged(); } } @@ -641,8 +643,7 @@ namespace Tizen.NUI.BaseComponents get { bool ret = false; - PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); - imageMap?.Find(ImageVisualProperty.CropToMask)?.Get(out ret); + Image.Find(ImageVisualProperty.CropToMask)?.Get(out ret); return ret; } @@ -650,7 +651,7 @@ namespace Tizen.NUI.BaseComponents { PropertyMap temp = new PropertyMap(); temp.Insert(ImageVisualProperty.CropToMask, new PropertyValue(value)); - + PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); imageMap.Merge(temp); @@ -673,8 +674,7 @@ namespace Tizen.NUI.BaseComponents get { int ret = (int)FittingModeType.ShrinkToFit; - PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); - imageMap?.Find(ImageVisualProperty.FittingMode)?.Get(out ret); + Image.Find(ImageVisualProperty.FittingMode)?.Get(out ret); return (FittingModeType)ret; } @@ -682,10 +682,10 @@ namespace Tizen.NUI.BaseComponents { PropertyMap temp = new PropertyMap(); temp.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int)value)); - + PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); imageMap.Merge(temp); - + SetValue(ImageProperty, imageMap); NotifyPropertyChanged(); } @@ -706,8 +706,7 @@ namespace Tizen.NUI.BaseComponents get { int ret = -1; - PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); - imageMap?.Find(ImageVisualProperty.DesiredWidth)?.Get(out ret); + Image.Find(ImageVisualProperty.DesiredWidth)?.Get(out ret); return ret; } @@ -715,10 +714,10 @@ namespace Tizen.NUI.BaseComponents { PropertyMap temp = new PropertyMap(); temp.Insert(ImageVisualProperty.DesiredWidth, new PropertyValue(value)); - + PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); imageMap.Merge(temp); - + SetValue(ImageProperty, imageMap); NotifyPropertyChanged(); } @@ -737,8 +736,7 @@ namespace Tizen.NUI.BaseComponents get { int ret = -1; - PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); - imageMap?.Find(ImageVisualProperty.DesiredHeight)?.Get(out ret); + Image.Find(ImageVisualProperty.DesiredHeight)?.Get(out ret); return ret; } @@ -746,10 +744,10 @@ namespace Tizen.NUI.BaseComponents { PropertyMap temp = new PropertyMap(); temp.Insert(ImageVisualProperty.DesiredHeight, new PropertyValue(value)); - + PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); imageMap.Merge(temp); - + SetValue(ImageProperty, imageMap); NotifyPropertyChanged(); } @@ -770,8 +768,7 @@ namespace Tizen.NUI.BaseComponents get { int ret = (int)WrapModeType.Default; - PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); - imageMap?.Find(ImageVisualProperty.WrapModeU)?.Get(out ret); + Image.Find(ImageVisualProperty.WrapModeU)?.Get(out ret); return (WrapModeType)ret; } @@ -779,10 +776,10 @@ namespace Tizen.NUI.BaseComponents { PropertyMap temp = new PropertyMap(); temp.Insert(ImageVisualProperty.WrapModeU, new PropertyValue((int)value)); - + PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); imageMap.Merge(temp); - + SetValue(ImageProperty, imageMap); NotifyPropertyChanged(); } @@ -803,8 +800,7 @@ namespace Tizen.NUI.BaseComponents get { int ret = (int)WrapModeType.Default; - PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); - imageMap?.Find(ImageVisualProperty.WrapModeV)?.Get(out ret); + Image.Find(ImageVisualProperty.WrapModeV)?.Get(out ret); return (WrapModeType)ret; } @@ -812,16 +808,15 @@ namespace Tizen.NUI.BaseComponents { PropertyMap temp = new PropertyMap(); temp.Insert(ImageVisualProperty.WrapModeV, new PropertyValue((int)value)); - + PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); imageMap.Merge(temp); - + SetValue(ImageProperty, imageMap); NotifyPropertyChanged(); } } - internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImageView obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; @@ -829,10 +824,9 @@ namespace Tizen.NUI.BaseComponents internal void SetImage(string url, Uint16Pair size) { + _url = url; Interop.ImageView.ImageView_SetImage__SWIG_2(swigCPtr, url, Uint16Pair.getCPtr(size)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - - UpdateImage(ImageVisualProperty.URL, new PropertyValue(url)); } internal ViewResourceReadySignal ResourceReadySignal(View view) @@ -866,6 +860,10 @@ namespace Tizen.NUI.BaseComponents //You should release all of your own disposable objects here. _border?.Dispose(); _border = null; + _nPatchMap?.Dispose(); + _nPatchMap = null; + _image?.Dispose(); + _image = null; } //Release your own unmanaged resources here. @@ -900,30 +898,59 @@ namespace Tizen.NUI.BaseComponents } } - private void UpdateImage(int key, PropertyValue value) + private void UpdateImage() { - PropertyMap temp = new PropertyMap(); - temp.Insert(key, value); - - if (_border != null) + if (_url != null && _url != "") { - temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch)); + if (_border != null) + { // for nine-patch image + _nPatchMap = new PropertyMap(); + _nPatchMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch)); + _nPatchMap.Add(NpatchImageVisualProperty.URL, new PropertyValue(_url)); + _nPatchMap.Add(NpatchImageVisualProperty.Border, new PropertyValue(_border)); + if (_borderOnly != null) { _nPatchMap.Add(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)_borderOnly)); } + if (_synchronousLoading != null) { _nPatchMap.Add(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading)); } + if (_orientationCorrection != null) { _nPatchMap.Add(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)_orientationCorrection)); } + SetProperty(ImageView.Property.IMAGE, new PropertyValue(_nPatchMap)); + _imageType = ImageType.Npatch; + } + else if (_synchronousLoading != null || _orientationCorrection != null) + { // for normal image, with synchronous loading property + PropertyMap imageMap = new PropertyMap(); + imageMap.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image)); + imageMap.Add(ImageVisualProperty.URL, new PropertyValue(_url)); + if (_synchronousLoading != null) { imageMap.Add(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading)); } + if (_orientationCorrection != null) { imageMap.Add(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)_orientationCorrection)); } + SetProperty(ImageView.Property.IMAGE, new PropertyValue(imageMap)); + + _imageType = ImageType.Specific; + } + else + { // just for normal image + SetProperty(ImageView.Property.IMAGE, new PropertyValue(_url)); + _imageType = ImageType.Normal; + } } else { - temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image)); - temp.Insert(ImageVisualProperty.BorderOnly, new PropertyValue((false))); + //Image property is set and used + PropertyMap map = new PropertyMap(); + map.Insert(ImageVisualProperty.URL, new PropertyValue("")); + if (_synchronousLoading != null) + { + map.Insert(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)_synchronousLoading)); + } + if (_orientationCorrection != null) + { + map.Insert(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)_orientationCorrection)); + } + if (_image != null) + { + map.Merge(_image); + } + SetProperty(ImageView.Property.IMAGE, new PropertyValue(map)); + _imageType = ImageType.Normal; } - - - PropertyMap imageMap = (PropertyMap)GetValue(ImageProperty); - imageMap.Merge(temp); - - SetValue(ImageProperty, imageMap); - NotifyPropertyChanged(); - - temp.Dispose(); - temp = null; } private void OnResourceLoaded(IntPtr view) diff --git a/src/Tizen.NUI/src/public/Window.cs b/src/Tizen.NUI/src/public/Window.cs index 184b28ed4..0f159b729 100755 --- a/src/Tizen.NUI/src/public/Window.cs +++ b/src/Tizen.NUI/src/public/Window.cs @@ -1302,7 +1302,8 @@ namespace Tizen.NUI internal Vector2 GetSize() { - Vector2 ret = new Vector2(Interop.Window.GetSize(swigCPtr), true); + var val = new Uint16Pair(Interop.Window.GetSize(swigCPtr), false); + Vector2 ret = new Vector2(val.GetWidth(), val.GetHeight()); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } -- 2.34.1