2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.ComponentModel;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.Binding;
22 namespace Tizen.NUI.BaseComponents
24 public partial class ImageView
26 /// Intenal used, will never be opened.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create(nameof(ImageView.ResourceUrl), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
30 var imageView = (ImageView)bindable;
32 if (newValue is Selector<string> selector)
34 imageView.ResourceUrlSelector = selector;
38 imageView.resourceUrlSelector?.Reset(imageView);
39 imageView.SetResourceUrl((string)newValue);
42 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
44 var imageView = (ImageView)bindable;
47 imageView.GetCachedImageVisualProperty(ImageVisualProperty.URL)?.Get(out ret);
52 /// Intenal used, will never be opened.
53 [EditorBrowsable(EditorBrowsableState.Never)]
54 public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(ImageView.Image), typeof(PropertyMap), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
56 var imageView = (ImageView)bindable;
59 PropertyMap map = (PropertyMap)newValue;
60 if (imageView.IsCreateByXaml)
62 string url = "", alphaMaskURL = "", auxiliaryImageURL = "";
63 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
64 PropertyValue urlValue = map.Find(NDalic.ImageVisualUrl);
66 if (urlValue != null) ret = urlValue.Get(out url);
67 PropertyMap mmap = new PropertyMap();
68 if (ret && url.StartsWith("*Resource*"))
70 url = url.Replace("*Resource*", resource);
71 mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(url));
75 PropertyValue alphaMaskUrlValue = map.Find(NDalic.ImageVisualAlphaMaskUrl);
76 if (alphaMaskUrlValue != null) ret = alphaMaskUrlValue.Get(out alphaMaskURL);
77 if (ret && alphaMaskURL.StartsWith("*Resource*"))
79 alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource);
80 mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(alphaMaskURL));
84 PropertyValue auxiliaryImageURLValue = map.Find(NDalic.ImageVisualAuxiliaryImageUrl);
85 if (auxiliaryImageURLValue != null) ret = auxiliaryImageURLValue.Get(out auxiliaryImageURL);
86 if (ret && auxiliaryImageURL.StartsWith("*Resource*"))
88 auxiliaryImageURL = auxiliaryImageURL.Replace("*Resource*", resource);
89 mmap.Insert(NDalic.ImageVisualAuxiliaryImageUrl, new PropertyValue(auxiliaryImageURL));
94 if (imageView._border == null)
96 // Image properties are changed hardly. We should ignore lazy UpdateImage
97 imageView.imagePropertyUpdatedFlag = false;
98 imageView.cachedImagePropertyMap?.Dispose();
99 imageView.cachedImagePropertyMap = null;
100 imageView.MergeCachedImageVisualProperty(map);
102 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
106 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
108 var imageView = (ImageView)bindable;
109 if (imageView._border == null)
111 // Sync as current properties
112 imageView.UpdateImage();
114 // Get current properties force.
115 PropertyMap returnValue = new PropertyMap();
116 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(returnValue);
118 // Update cached property map
119 if (returnValue != null)
121 imageView.MergeCachedImageVisualProperty(returnValue);
131 /// Intenal used, will never be opened.
132 [EditorBrowsable(EditorBrowsableState.Never)]
133 public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create(nameof(PreMultipliedAlpha), typeof(bool), typeof(ImageView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
135 var imageView = (ImageView)bindable;
136 if (newValue != null)
138 if (imageView.imagePropertyUpdatedFlag)
140 // If imageView Property still not send to the dali, Append cached property.
141 imageView.UpdateImage(Visual.Property.PremultipliedAlpha, new PropertyValue((bool)newValue));
145 // Else, we don't need to re-create view. Get value from current ImageView.
146 Object.InternalSetPropertyBool(imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, (bool)newValue);
150 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
152 var imageView = (ImageView)bindable;
155 if (imageView.imagePropertyUpdatedFlag)
157 // If imageView Property still not send to the dali, just get cached property.
158 imageView.GetCachedImageVisualProperty(Visual.Property.PremultipliedAlpha)?.Get(out temp);
162 // Else, PremultipliedAlpha may not setuped in cached property. Get value from current ImageView.
163 temp = Object.InternalGetPropertyBool(imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha);
168 /// Intenal used, will never be opened.
169 [EditorBrowsable(EditorBrowsableState.Never)]
170 public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
172 var imageView = (ImageView)bindable;
173 if (newValue != null)
176 Object.InternalSetPropertyVector4(imageView.SwigCPtr, ImageView.Property.PixelArea, ((RelativeVector4)newValue).SwigCPtr);
179 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
181 var imageView = (ImageView)bindable;
183 if (imageView.internalPixelArea == null)
185 imageView.internalPixelArea = new RelativeVector4(imageView.OnPixelAreaChanged, 0, 0, 0, 0);
187 Object.InternalRetrievingPropertyVector4(imageView.SwigCPtr, ImageView.Property.PixelArea, imageView.internalPixelArea.SwigCPtr);
188 return imageView.internalPixelArea;
191 /// Intenal used, will never be opened.
192 [EditorBrowsable(EditorBrowsableState.Never)]
193 public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
195 var imageView = (ImageView)bindable;
196 imageView.borderSelector?.Reset(imageView);
198 if (newValue is Selector<Rectangle> selector)
200 if (selector.HasAll()) imageView.SetBorder(selector.All);
201 else imageView.borderSelector = new TriggerableSelector<Rectangle>(imageView, selector, imageView.SetBorder, true);
205 imageView.SetBorder((Rectangle)newValue);
208 defaultValueCreator: (bindable) =>
210 var imageView = (ImageView)bindable;
211 return imageView._border;
214 /// Intenal used, will never be opened.
215 [EditorBrowsable(EditorBrowsableState.Never)]
216 public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
218 var imageView = (ImageView)bindable;
219 if (newValue != null)
221 if (oldValue != null)
223 bool oldBool = (bool)oldValue;
224 bool newBool = (bool)newValue;
225 if (oldBool == newBool)
230 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
233 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
235 var imageView = (ImageView)bindable;
238 imageView.GetCachedImageVisualProperty(NpatchImageVisualProperty.BorderOnly)?.Get(out ret);
243 /// Intenal used, will never be opened.
244 [EditorBrowsable(EditorBrowsableState.Never)]
245 public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
247 var imageView = (ImageView)bindable;
248 if (newValue != null)
250 if (oldValue != null)
252 bool oldBool = (bool)oldValue;
253 bool newBool = (bool)newValue;
254 if (oldBool == newBool)
259 // Note : We need to create new visual if previous visual was async, and now we set value as sync.
260 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue), (bool)newValue);
263 defaultValueCreator: (bindable) =>
265 var imageView = (ImageView)bindable;
268 imageView.GetCachedImageVisualProperty(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
273 /// This will be public opened in tizen_7.0 after ACR done. Before ACR, need to be hidden as inhouse API.
274 [EditorBrowsable(EditorBrowsableState.Never)]
275 public static readonly BindableProperty SynchronousLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
277 var imageView = (ImageView)bindable;
278 if (newValue != null)
280 if (oldValue != null)
282 bool oldBool = (bool)oldValue;
283 bool newBool = (bool)newValue;
284 if (oldBool == newBool)
289 // Note : We need to create new visual if previous visual was async, and now we set value as sync.
290 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue), (bool)newValue);
293 defaultValueCreator: (bindable) =>
295 var imageView = (ImageView)bindable;
298 imageView.GetCachedImageVisualProperty(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
303 /// Intenal used, will never be opened.
304 [EditorBrowsable(EditorBrowsableState.Never)]
305 public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
307 var imageView = (ImageView)bindable;
308 if (newValue != null)
310 if (oldValue != null)
312 bool oldBool = (bool)oldValue;
313 bool newBool = (bool)newValue;
314 if (oldBool == newBool)
319 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
322 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
324 var imageView = (ImageView)bindable;
328 imageView.GetCachedImageVisualProperty(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
334 /// MaskingModeProperty
336 [EditorBrowsable(EditorBrowsableState.Never)]
337 public static readonly BindableProperty MaskingModeProperty = BindableProperty.Create(nameof(MaskingMode), typeof(MaskingModeType), typeof(ImageView), default(MaskingModeType), propertyChanged: (bindable, oldValue, newValue) =>
339 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
340 if (newValue != null)
342 instance.InternalMaskingMode = (ImageView.MaskingModeType)newValue;
345 defaultValueCreator: (bindable) =>
347 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
348 return instance.InternalMaskingMode;
354 [EditorBrowsable(EditorBrowsableState.Never)]
355 public static readonly BindableProperty ImageMapProperty = BindableProperty.Create(nameof(ImageMap), typeof(Tizen.NUI.PropertyMap), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
357 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
358 if (newValue != null)
360 instance.InternalImageMap = (Tizen.NUI.PropertyMap)newValue;
363 defaultValueCreator: (bindable) =>
365 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
366 return instance.InternalImageMap;
370 /// AlphaMaskURLProperty
372 [EditorBrowsable(EditorBrowsableState.Never)]
373 public static readonly BindableProperty AlphaMaskURLProperty = BindableProperty.Create(nameof(AlphaMaskURL), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
375 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
376 if (newValue != null)
378 instance.InternalAlphaMaskURL = (string)newValue;
381 defaultValueCreator: (bindable) =>
383 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
384 return instance.InternalAlphaMaskURL;
388 /// CropToMaskProperty
390 [EditorBrowsable(EditorBrowsableState.Never)]
391 public static readonly BindableProperty CropToMaskProperty = BindableProperty.Create(nameof(CropToMask), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
393 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
394 if (newValue != null)
396 instance.InternalCropToMask = (bool)newValue;
399 defaultValueCreator: (bindable) =>
401 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
402 return instance.InternalCropToMask;
406 /// FittingModeProperty
408 [EditorBrowsable(EditorBrowsableState.Never)]
409 public static readonly BindableProperty FittingModeProperty = BindableProperty.Create(nameof(FittingMode), typeof(FittingModeType), typeof(ImageView), default(FittingModeType), propertyChanged: (bindable, oldValue, newValue) =>
411 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
412 if (newValue != null)
414 instance.InternalFittingMode = (Tizen.NUI.FittingModeType)newValue;
417 defaultValueCreator: (bindable) =>
419 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
420 return instance.InternalFittingMode;
424 /// DesiredWidthProperty
426 [EditorBrowsable(EditorBrowsableState.Never)]
427 public static readonly BindableProperty DesiredWidthProperty = BindableProperty.Create(nameof(DesiredWidth), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
429 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
430 if (newValue != null)
432 instance.InternalDesiredWidth = (int)newValue;
435 defaultValueCreator: (bindable) =>
437 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
438 return instance.InternalDesiredWidth;
442 /// DesiredHeightProperty
444 [EditorBrowsable(EditorBrowsableState.Never)]
445 public static readonly BindableProperty DesiredHeightProperty = BindableProperty.Create(nameof(DesiredHeight), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
447 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
448 if (newValue != null)
450 instance.InternalDesiredHeight = (int)newValue;
453 defaultValueCreator: (bindable) =>
455 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
456 return instance.InternalDesiredHeight;
460 /// ReleasePolicyProperty
462 [EditorBrowsable(EditorBrowsableState.Never)]
463 public static readonly BindableProperty ReleasePolicyProperty = BindableProperty.Create(nameof(ReleasePolicy), typeof(ReleasePolicyType), typeof(ImageView), default(ReleasePolicyType), propertyChanged: (bindable, oldValue, newValue) =>
465 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
466 if (newValue != null)
468 instance.InternalReleasePolicy = (Tizen.NUI.ReleasePolicyType)newValue;
471 defaultValueCreator: (bindable) =>
473 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
474 return instance.InternalReleasePolicy;
478 /// WrapModeUProperty
480 [EditorBrowsable(EditorBrowsableState.Never)]
481 public static readonly BindableProperty WrapModeUProperty = BindableProperty.Create(nameof(WrapModeU), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
483 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
484 if (newValue != null)
486 instance.InternalWrapModeU = (Tizen.NUI.WrapModeType)newValue;
489 defaultValueCreator: (bindable) =>
491 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
492 return instance.InternalWrapModeU;
496 /// WrapModeVProperty
498 [EditorBrowsable(EditorBrowsableState.Never)]
499 public static readonly BindableProperty WrapModeVProperty = BindableProperty.Create(nameof(WrapModeV), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
501 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
502 if (newValue != null)
504 instance.InternalWrapModeV = (Tizen.NUI.WrapModeType)newValue;
507 defaultValueCreator: (bindable) =>
509 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
510 return instance.InternalWrapModeV;
514 /// AdjustViewSizeProperty
516 [EditorBrowsable(EditorBrowsableState.Never)]
517 public static readonly BindableProperty AdjustViewSizeProperty = BindableProperty.Create(nameof(AdjustViewSize), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
519 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
520 if (newValue != null)
522 instance.adjustViewSize = (bool)newValue;
525 defaultValueCreator: (bindable) =>
527 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
528 return instance.adjustViewSize;
532 /// PlaceHolderUrlProperty
534 [EditorBrowsable(EditorBrowsableState.Never)]
535 public static readonly BindableProperty PlaceHolderUrlProperty = BindableProperty.Create(nameof(PlaceHolderUrl), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
537 var imageView = (Tizen.NUI.BaseComponents.ImageView)bindable;
538 if (newValue != null)
540 Object.InternalSetPropertyString(imageView.SwigCPtr, ImageView.Property.PlaceHolderUrl, (string)newValue );
543 defaultValueCreator: (bindable) =>
545 var imageView = (Tizen.NUI.BaseComponents.ImageView)bindable;
546 return Object.InternalGetPropertyString(imageView.SwigCPtr, ImageView.Property.PlaceHolderUrl);
549 /// Intenal used, will never be opened.
550 [EditorBrowsable(EditorBrowsableState.Never)]
551 public static readonly BindableProperty TransitionEffectProperty = BindableProperty.Create(nameof(TransitionEffect), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
553 var imageView = (ImageView)bindable;
554 if (newValue != null)
556 Object.InternalSetPropertyBool(imageView.SwigCPtr, ImageView.Property.TransitionEffect, (bool)newValue);
559 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
561 var imageView = (ImageView)bindable;
562 return Object.InternalGetPropertyBool(imageView.SwigCPtr, ImageView.Property.TransitionEffect);