dcaa6d8e5be75c42441860567881bbd4ffca98f6
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ImageViewBindableProperty.cs
1 /*
2  * Copyright(c) 2021 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
18 using System.ComponentModel;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.BaseComponents
23 {
24     public partial class ImageView
25     {
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) =>
29         {
30             var imageView = (ImageView)bindable;
31
32             if (newValue is Selector<string> selector)
33             {
34                 imageView.ResourceUrlSelector = selector;
35             }
36             else
37             {
38                 imageView.resourceUrlSelector?.Reset(imageView);
39                 imageView.SetResourceUrl((string)newValue);
40             }
41         },
42         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
43         {
44             var imageView = (ImageView)bindable;
45             string ret = "";
46
47             imageView.GetCachedImageVisualProperty(ImageVisualProperty.URL)?.Get(out ret);
48
49             return ret;
50         }));
51
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) =>
55         {
56             var imageView = (ImageView)bindable;
57             if (newValue != null)
58             {
59                 PropertyMap map = (PropertyMap)newValue;
60                 if (imageView.IsCreateByXaml)
61                 {
62                     string url = "", alphaMaskURL = "", auxiliaryImageURL = "";
63                     string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
64                     PropertyValue urlValue = map.Find(NDalic.ImageVisualUrl);
65                     bool ret = false;
66                     if (urlValue != null) ret = urlValue.Get(out url);
67                     PropertyMap mmap = new PropertyMap();
68                     if (ret && url.StartsWith("*Resource*"))
69                     {
70                         url = url.Replace("*Resource*", resource);
71                         mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(url));
72                     }
73
74                     ret = false;
75                     PropertyValue alphaMaskUrlValue = map.Find(NDalic.ImageVisualAlphaMaskUrl);
76                     if (alphaMaskUrlValue != null) ret = alphaMaskUrlValue.Get(out alphaMaskURL);
77                     if (ret && alphaMaskURL.StartsWith("*Resource*"))
78                     {
79                         alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource);
80                         mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(alphaMaskURL));
81                     }
82
83                     ret = false;
84                     PropertyValue auxiliaryImageURLValue = map.Find(NDalic.ImageVisualAuxiliaryImageUrl);
85                     if (auxiliaryImageURLValue != null) ret = auxiliaryImageURLValue.Get(out auxiliaryImageURL);
86                     if (ret && auxiliaryImageURL.StartsWith("*Resource*"))
87                     {
88                         auxiliaryImageURL = auxiliaryImageURL.Replace("*Resource*", resource);
89                         mmap.Insert(NDalic.ImageVisualAuxiliaryImageUrl, new PropertyValue(auxiliaryImageURL));
90                     }
91
92                     map.Merge(mmap);
93                 }
94                 if (imageView._border == null)
95                 {
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);
101
102                     Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
103                 }
104             }
105         }),
106         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
107         {
108             var imageView = (ImageView)bindable;
109             if (imageView._border == null)
110             {
111                 // Sync as current properties
112                 imageView.UpdateImage();
113
114                 // Get current properties force.
115                 PropertyMap returnValue = new PropertyMap();
116                 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(returnValue);
117
118                 // Update cached property map
119                 if (returnValue != null)
120                 {
121                     imageView.MergeCachedImageVisualProperty(returnValue);
122                 }
123                 return returnValue;
124             }
125             else
126             {
127                 return null;
128             }
129         }));
130
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) =>
134         {
135             var imageView = (ImageView)bindable;
136             if (newValue != null)
137             {
138                 if (imageView.imagePropertyUpdatedFlag)
139                 {
140                     // If imageView Property still not send to the dali, Append cached property.
141                     imageView.UpdateImage(Visual.Property.PremultipliedAlpha, new PropertyValue((bool)newValue));
142                 }
143                 else
144                 {
145                     // Else, we don't need to re-create view. Get value from current ImageView.
146 #if NUI_PROPERTY_CHANGE_2
147                     Object.InternalSetPropertyBool(imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, (bool)newValue);
148 #else
149                     Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, new Tizen.NUI.PropertyValue((bool)newValue));
150 #endif                    
151                 }
152             }
153         }),
154         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
155         {
156             var imageView = (ImageView)bindable;
157             bool temp = false;
158
159             if (imageView.imagePropertyUpdatedFlag)
160             {
161                 // If imageView Property still not send to the dali, just get cached property.
162                 imageView.GetCachedImageVisualProperty(Visual.Property.PremultipliedAlpha)?.Get(out temp);
163             }
164             else
165             {
166                 // Else, PremultipliedAlpha may not setuped in cached property. Get value from current ImageView.
167 #if NUI_PROPERTY_CHANGE_2
168                 temp = Object.InternalGetPropertyBool(imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha);
169 #else
170                 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha).Get(out temp);
171 #endif                
172             }
173             return temp;
174         }));
175
176         /// Intenal used, will never be opened.
177         [EditorBrowsable(EditorBrowsableState.Never)]
178         public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
179         {
180             var imageView = (ImageView)bindable;
181             if (newValue != null)
182             {
183 #if NUI_PROPERTY_CHANGE_2
184                 Object.InternalSetPropertyVector4(imageView.SwigCPtr, ImageView.Property.PixelArea, ((RelativeVector4)newValue).SwigCPtr);
185 #else
186                 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
187 #endif
188             }
189         }),
190         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
191         {
192             var imageView = (ImageView)bindable;
193 #if NUI_PROPERTY_CHANGE_2
194             if (imageView.internalPixelArea == null)
195             {
196                 imageView.internalPixelArea = new RelativeVector4(imageView.OnPixelAreaChanged, 0, 0, 0, 0);
197             }
198             Object.InternalRetrievingPropertyVector4(imageView.SwigCPtr, ImageView.Property.PixelArea, imageView.internalPixelArea.SwigCPtr);
199             return imageView.internalPixelArea;
200 #else
201             Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
202             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea).Get(temp);
203             RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
204             return relativeTemp;
205 #endif            
206         }));
207
208         /// Intenal used, will never be opened.
209         [EditorBrowsable(EditorBrowsableState.Never)]
210         public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
211         {
212             var imageView = (ImageView)bindable;
213             imageView.borderSelector?.Reset(imageView);
214
215             if (newValue is Selector<Rectangle> selector)
216             {
217                 if (selector.HasAll()) imageView.SetBorder(selector.All);
218                 else imageView.borderSelector = new TriggerableSelector<Rectangle>(imageView, selector, imageView.SetBorder, true);
219             }
220             else
221             {
222                 imageView.SetBorder((Rectangle)newValue);
223             }
224         },
225         defaultValueCreator: (bindable) =>
226         {
227             var imageView = (ImageView)bindable;
228             return imageView._border;
229         });
230
231         /// Intenal used, will never be opened.
232         [EditorBrowsable(EditorBrowsableState.Never)]
233         public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
234         {
235             var imageView = (ImageView)bindable;
236             if (newValue != null)
237             {
238                 if (oldValue != null)
239                 {
240                     bool oldBool = (bool)oldValue;
241                     bool newBool = (bool)newValue;
242                     if (oldBool == newBool)
243                     {
244                         return;
245                     }
246                 }
247                 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
248             }
249         },
250         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
251         {
252             var imageView = (ImageView)bindable;
253             bool ret = false;
254
255             imageView.GetCachedImageVisualProperty(NpatchImageVisualProperty.BorderOnly)?.Get(out ret);
256
257             return ret;
258         }));
259
260         /// Intenal used, will never be opened.
261         [EditorBrowsable(EditorBrowsableState.Never)]
262         public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
263         {
264             var imageView = (ImageView)bindable;
265             if (newValue != null)
266             {
267                 if (oldValue != null)
268                 {
269                     bool oldBool = (bool)oldValue;
270                     bool newBool = (bool)newValue;
271                     if (oldBool == newBool)
272                     {
273                         return;
274                     }
275                 }
276                 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
277             }
278         },
279         defaultValueCreator: (bindable) =>
280         {
281             var imageView = (ImageView)bindable;
282             bool ret = false;
283
284             imageView.GetCachedImageVisualProperty(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
285
286             return ret;
287         });
288
289         /// This will be public opened in tizen_7.0 after ACR done. Before ACR, need to be hidden as inhouse API.
290         [EditorBrowsable(EditorBrowsableState.Never)]
291         public static readonly BindableProperty SynchronousLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
292         {
293             var imageView = (ImageView)bindable;
294             if (newValue != null)
295             {
296                 if (oldValue != null)
297                 {
298                     bool oldBool = (bool)oldValue;
299                     bool newBool = (bool)newValue;
300                     if (oldBool == newBool)
301                     {
302                         return;
303                     }
304                 }
305                 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
306             }
307         },
308         defaultValueCreator: (bindable) =>
309         {
310             var imageView = (ImageView)bindable;
311             bool ret = false;
312
313             imageView.GetCachedImageVisualProperty(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
314
315             return ret;
316         });
317
318         /// Intenal used, will never be opened.
319         [EditorBrowsable(EditorBrowsableState.Never)]
320         public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
321         {
322             var imageView = (ImageView)bindable;
323             if (newValue != null)
324             {
325                 if (oldValue != null)
326                 {
327                     bool oldBool = (bool)oldValue;
328                     bool newBool = (bool)newValue;
329                     if (oldBool == newBool)
330                     {
331                         return;
332                     }
333                 }
334                 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
335             }
336         },
337         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
338         {
339             var imageView = (ImageView)bindable;
340
341             bool ret = false;
342
343             imageView.GetCachedImageVisualProperty(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
344
345             return ret;
346         }));
347
348         /// <summary>
349         /// MaskingModeProperty
350         /// </summary>
351         [EditorBrowsable(EditorBrowsableState.Never)]
352         public static readonly BindableProperty MaskingModeProperty = BindableProperty.Create(nameof(MaskingMode), typeof(MaskingModeType), typeof(ImageView), default(MaskingModeType), propertyChanged: (bindable, oldValue, newValue) =>
353         {
354             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
355             if (newValue != null)
356             {
357                 instance.InternalMaskingMode = (ImageView.MaskingModeType)newValue;
358             }
359         },
360         defaultValueCreator: (bindable) =>
361         {
362             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
363             return instance.InternalMaskingMode;
364         });
365
366         /// <summary>
367         /// ImageMapProperty
368         /// </summary>
369         [EditorBrowsable(EditorBrowsableState.Never)]
370         public static readonly BindableProperty ImageMapProperty = BindableProperty.Create(nameof(ImageMap), typeof(Tizen.NUI.PropertyMap), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
371         {
372             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
373             if (newValue != null)
374             {
375                 instance.InternalImageMap = (Tizen.NUI.PropertyMap)newValue;
376             }
377         },
378         defaultValueCreator: (bindable) =>
379         {
380             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
381             return instance.InternalImageMap;
382         });
383
384         /// <summary>
385         /// AlphaMaskURLProperty
386         /// </summary>
387         [EditorBrowsable(EditorBrowsableState.Never)]
388         public static readonly BindableProperty AlphaMaskURLProperty = BindableProperty.Create(nameof(AlphaMaskURL), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
389         {
390             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
391             if (newValue != null)
392             {
393                 instance.InternalAlphaMaskURL = (string)newValue;
394             }
395         },
396         defaultValueCreator: (bindable) =>
397         {
398             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
399             return instance.InternalAlphaMaskURL;
400         });
401
402         /// <summary>
403         /// CropToMaskProperty
404         /// </summary>
405         [EditorBrowsable(EditorBrowsableState.Never)]
406         public static readonly BindableProperty CropToMaskProperty = BindableProperty.Create(nameof(CropToMask), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
407         {
408             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
409             if (newValue != null)
410             {
411                 instance.InternalCropToMask = (bool)newValue;
412             }
413         },
414         defaultValueCreator: (bindable) =>
415         {
416             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
417             return instance.InternalCropToMask;
418         });
419
420         /// <summary>
421         /// FittingModeProperty
422         /// </summary>
423         [EditorBrowsable(EditorBrowsableState.Never)]
424         public static readonly BindableProperty FittingModeProperty = BindableProperty.Create(nameof(FittingMode), typeof(FittingModeType), typeof(ImageView), default(FittingModeType), propertyChanged: (bindable, oldValue, newValue) =>
425         {
426             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
427             if (newValue != null)
428             {
429                 instance.InternalFittingMode = (Tizen.NUI.FittingModeType)newValue;
430             }
431         },
432         defaultValueCreator: (bindable) =>
433         {
434             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
435             return instance.InternalFittingMode;
436         });
437
438         /// <summary>
439         /// DesiredWidthProperty
440         /// </summary>
441         [EditorBrowsable(EditorBrowsableState.Never)]
442         public static readonly BindableProperty DesiredWidthProperty = BindableProperty.Create(nameof(DesiredWidth), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
443         {
444             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
445             if (newValue != null)
446             {
447                 instance.InternalDesiredWidth = (int)newValue;
448             }
449         },
450         defaultValueCreator: (bindable) =>
451         {
452             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
453             return instance.InternalDesiredWidth;
454         });
455
456         /// <summary>
457         /// DesiredHeightProperty
458         /// </summary>
459         [EditorBrowsable(EditorBrowsableState.Never)]
460         public static readonly BindableProperty DesiredHeightProperty = BindableProperty.Create(nameof(DesiredHeight), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
461         {
462             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
463             if (newValue != null)
464             {
465                 instance.InternalDesiredHeight = (int)newValue;
466             }
467         },
468         defaultValueCreator: (bindable) =>
469         {
470             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
471             return instance.InternalDesiredHeight;
472         });
473
474         /// <summary>
475         /// ReleasePolicyProperty
476         /// </summary>
477         [EditorBrowsable(EditorBrowsableState.Never)]
478         public static readonly BindableProperty ReleasePolicyProperty = BindableProperty.Create(nameof(ReleasePolicy), typeof(ReleasePolicyType), typeof(ImageView), default(ReleasePolicyType), propertyChanged: (bindable, oldValue, newValue) =>
479         {
480             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
481             if (newValue != null)
482             {
483                 instance.InternalReleasePolicy = (Tizen.NUI.ReleasePolicyType)newValue;
484             }
485         },
486         defaultValueCreator: (bindable) =>
487         {
488             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
489             return instance.InternalReleasePolicy;
490         });
491
492         /// <summary>
493         /// WrapModeUProperty
494         /// </summary>
495         [EditorBrowsable(EditorBrowsableState.Never)]
496         public static readonly BindableProperty WrapModeUProperty = BindableProperty.Create(nameof(WrapModeU), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
497         {
498             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
499             if (newValue != null)
500             {
501                 instance.InternalWrapModeU = (Tizen.NUI.WrapModeType)newValue;
502             }
503         },
504         defaultValueCreator: (bindable) =>
505         {
506             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
507             return instance.InternalWrapModeU;
508         });
509
510         /// <summary>
511         /// WrapModeVProperty
512         /// </summary>
513         [EditorBrowsable(EditorBrowsableState.Never)]
514         public static readonly BindableProperty WrapModeVProperty = BindableProperty.Create(nameof(WrapModeV), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
515         {
516             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
517             if (newValue != null)
518             {
519                 instance.InternalWrapModeV = (Tizen.NUI.WrapModeType)newValue;
520             }
521         },
522         defaultValueCreator: (bindable) =>
523         {
524             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
525             return instance.InternalWrapModeV;
526         });
527
528         /// <summary>
529         /// AdjustViewSizeProperty
530         /// </summary>
531         [EditorBrowsable(EditorBrowsableState.Never)]
532         public static readonly BindableProperty AdjustViewSizeProperty = BindableProperty.Create(nameof(AdjustViewSize), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
533         {
534             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
535             if (newValue != null)
536             {
537                 instance.adjustViewSize = (bool)newValue;
538             }
539         },
540         defaultValueCreator: (bindable) =>
541         {
542             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
543             return instance.adjustViewSize;
544         });
545     }
546 }