[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[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._imagePropertyMap?.Find(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._imagePropertyMap?.Dispose();
99                     imageView._imagePropertyMap = null;
100                     if(map != null)
101                     {
102                         imageView._imagePropertyMap = new PropertyMap(map);
103                     }
104                     Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
105                 }
106             }
107         }),
108         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
109         {
110             var imageView = (ImageView)bindable;
111             if (imageView._border == null)
112             {
113                 // Get current properties force.
114                 // TODO: Need to make some flag that we only need cached property map.
115                 PropertyMap temp = new PropertyMap();
116                 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(temp);
117                 return temp;
118             }
119             else
120             {
121                 return null;
122             }
123         }));
124
125         /// Intenal used, will never be opened.
126         [EditorBrowsable(EditorBrowsableState.Never)]
127         public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create(nameof(PreMultipliedAlpha), typeof(bool), typeof(ImageView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
128         {
129             var imageView = (ImageView)bindable;
130             if (newValue != null)
131             {
132                 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, new Tizen.NUI.PropertyValue((bool)newValue));
133             }
134         }),
135         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
136         {
137             var imageView = (ImageView)bindable;
138             bool temp = false;
139             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha).Get(out temp);
140             return temp;
141         }));
142
143         /// Intenal used, will never be opened.
144         [EditorBrowsable(EditorBrowsableState.Never)]
145         public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
146         {
147             var imageView = (ImageView)bindable;
148             if (newValue != null)
149             {
150                 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
151             }
152         }),
153         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
154         {
155             var imageView = (ImageView)bindable;
156             Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
157             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea).Get(temp);
158             RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
159             return relativeTemp;
160         }));
161
162         /// Intenal used, will never be opened.
163         [EditorBrowsable(EditorBrowsableState.Never)]
164         public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
165         {
166             var imageView = (ImageView)bindable;
167             imageView.borderSelector?.Reset(imageView);
168
169             if (newValue is Selector<Rectangle> selector)
170             {
171                 if (selector.HasAll()) imageView.SetBorder(selector.All);
172                 else imageView.borderSelector = new TriggerableSelector<Rectangle>(imageView, selector, imageView.SetBorder, true);
173             }
174             else
175             {
176                 imageView.SetBorder((Rectangle)newValue);
177             }
178         },
179         defaultValueCreator: (bindable) =>
180         {
181             var imageView = (ImageView)bindable;
182             return imageView._border;
183         });
184
185         /// Intenal used, will never be opened.
186         [EditorBrowsable(EditorBrowsableState.Never)]
187         public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
188         {
189             var imageView = (ImageView)bindable;
190             if (newValue != null)
191             {
192                 if(oldValue != null)
193                 {
194                     bool oldBool = (bool)oldValue;
195                     bool newBool = (bool)newValue;
196                     if(oldBool == newBool)
197                     {
198                         return;
199                     }
200                 }
201                 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
202             }
203         },
204         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
205         {
206             var imageView = (ImageView)bindable;
207             bool ret = false;
208
209             imageView._imagePropertyMap?.Find(NpatchImageVisualProperty.BorderOnly)?.Get(out ret);
210
211             return ret;
212         }));
213
214         /// Intenal used, will never be opened.
215         [EditorBrowsable(EditorBrowsableState.Never)]
216         public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
217         {
218             var imageView = (ImageView)bindable;
219             if (newValue != null)
220             {
221                 if(oldValue != null)
222                 {
223                     bool oldBool = (bool)oldValue;
224                     bool newBool = (bool)newValue;
225                     if(oldBool == newBool)
226                     {
227                         return;
228                     }
229                 }
230                 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
231             }
232         },
233         defaultValueCreator: (bindable) =>
234         {
235             var imageView = (ImageView)bindable;
236             bool ret = false;
237
238             imageView._imagePropertyMap?.Find(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
239
240             return ret;
241         });
242
243         /// This will be public opened in tizen_7.0 after ACR done. Before ACR, need to be hidden as inhouse API.
244         [EditorBrowsable(EditorBrowsableState.Never)]
245         public static readonly BindableProperty SynchronousLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
246         {
247             var imageView = (ImageView)bindable;
248             if (newValue != null)
249             {
250                 if(oldValue != null)
251                 {
252                     bool oldBool = (bool)oldValue;
253                     bool newBool = (bool)newValue;
254                     if(oldBool == newBool)
255                     {
256                         return;
257                     }
258                 }
259                 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
260             }
261         },
262         defaultValueCreator: (bindable) =>
263         {
264             var imageView = (ImageView)bindable;
265             bool ret = false;
266
267             imageView._imagePropertyMap?.Find(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
268
269             return ret;
270         });
271
272         /// Intenal used, will never be opened.
273         [EditorBrowsable(EditorBrowsableState.Never)]
274         public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
275         {
276             var imageView = (ImageView)bindable;
277             if (newValue != null)
278             {
279                 if(oldValue != null)
280                 {
281                     bool oldBool = (bool)oldValue;
282                     bool newBool = (bool)newValue;
283                     if(oldBool == newBool)
284                     {
285                         return;
286                     }
287                 }
288                 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
289             }
290         },
291         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
292         {
293             var imageView = (ImageView)bindable;
294
295             bool ret = false;
296
297             imageView._imagePropertyMap?.Find(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
298
299             return ret;
300         }));
301
302         /// <summary>
303         /// ImageMapProperty
304         /// </summary>
305         [EditorBrowsable(EditorBrowsableState.Never)]
306         public static readonly BindableProperty ImageMapProperty = BindableProperty.Create(nameof(ImageMap), typeof(Tizen.NUI.PropertyMap), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
307         {
308             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
309             if (newValue != null)
310             {
311                 instance.InternalImageMap = (Tizen.NUI.PropertyMap)newValue;
312             }
313         },
314         defaultValueCreator: (bindable) =>
315         {
316             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
317             return instance.InternalImageMap;
318         });
319
320         /// <summary>
321         /// AlphaMaskURLProperty
322         /// </summary>
323         [EditorBrowsable(EditorBrowsableState.Never)]
324         public static readonly BindableProperty AlphaMaskURLProperty = BindableProperty.Create(nameof(AlphaMaskURL), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
325         {
326             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
327             if (newValue != null)
328             {
329                 instance.InternalAlphaMaskURL = (string)newValue;
330             }
331         },
332         defaultValueCreator: (bindable) =>
333         {
334             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
335             return instance.InternalAlphaMaskURL;
336         });
337
338         /// <summary>
339         /// CropToMaskProperty
340         /// </summary>
341         [EditorBrowsable(EditorBrowsableState.Never)]
342         public static readonly BindableProperty CropToMaskProperty = BindableProperty.Create(nameof(CropToMask), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
343         {
344             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
345             if (newValue != null)
346             {
347                 instance.InternalCropToMask = (bool)newValue;
348             }
349         },
350         defaultValueCreator: (bindable) =>
351         {
352             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
353             return instance.InternalCropToMask;
354         });
355
356         /// <summary>
357         /// FittingModeProperty
358         /// </summary>
359         [EditorBrowsable(EditorBrowsableState.Never)]
360         public static readonly BindableProperty FittingModeProperty = BindableProperty.Create(nameof(FittingMode), typeof(FittingModeType), typeof(ImageView), default(FittingModeType), propertyChanged: (bindable, oldValue, newValue) =>
361         {
362             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
363             if (newValue != null)
364             {
365                 instance.InternalFittingMode = (Tizen.NUI.FittingModeType)newValue;
366             }
367         },
368         defaultValueCreator: (bindable) =>
369         {
370             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
371             return instance.InternalFittingMode;
372         });
373
374         /// <summary>
375         /// DesiredWidthProperty
376         /// </summary>
377         [EditorBrowsable(EditorBrowsableState.Never)]
378         public static readonly BindableProperty DesiredWidthProperty = BindableProperty.Create(nameof(DesiredWidth), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
379         {
380             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
381             if (newValue != null)
382             {
383                 instance.InternalDesiredWidth = (int)newValue;
384             }
385         },
386         defaultValueCreator: (bindable) =>
387         {
388             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
389             return instance.InternalDesiredWidth;
390         });
391
392         /// <summary>
393         /// DesiredHeightProperty
394         /// </summary>
395         [EditorBrowsable(EditorBrowsableState.Never)]
396         public static readonly BindableProperty DesiredHeightProperty = BindableProperty.Create(nameof(DesiredHeight), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
397         {
398             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
399             if (newValue != null)
400             {
401                 instance.InternalDesiredHeight = (int)newValue;
402             }
403         },
404         defaultValueCreator: (bindable) =>
405         {
406             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
407             return instance.InternalDesiredHeight;
408         });
409
410         /// <summary>
411         /// ReleasePolicyProperty
412         /// </summary>
413         [EditorBrowsable(EditorBrowsableState.Never)]
414         public static readonly BindableProperty ReleasePolicyProperty = BindableProperty.Create(nameof(ReleasePolicy), typeof(ReleasePolicyType), typeof(ImageView), default(ReleasePolicyType), propertyChanged: (bindable, oldValue, newValue) =>
415         {
416             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
417             if (newValue != null)
418             {
419                 instance.InternalReleasePolicy = (Tizen.NUI.ReleasePolicyType)newValue;
420             }
421         },
422         defaultValueCreator: (bindable) =>
423         {
424             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
425             return instance.InternalReleasePolicy;
426         });
427
428         /// <summary>
429         /// WrapModeUProperty
430         /// </summary>
431         [EditorBrowsable(EditorBrowsableState.Never)]
432         public static readonly BindableProperty WrapModeUProperty = BindableProperty.Create(nameof(WrapModeU), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
433         {
434             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
435             if (newValue != null)
436             {
437                 instance.InternalWrapModeU = (Tizen.NUI.WrapModeType)newValue;
438             }
439         },
440         defaultValueCreator: (bindable) =>
441         {
442             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
443             return instance.InternalWrapModeU;
444         });
445
446         /// <summary>
447         /// WrapModeVProperty
448         /// </summary>
449         [EditorBrowsable(EditorBrowsableState.Never)]
450         public static readonly BindableProperty WrapModeVProperty = BindableProperty.Create(nameof(WrapModeV), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
451         {
452             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
453             if (newValue != null)
454             {
455                 instance.InternalWrapModeV = (Tizen.NUI.WrapModeType)newValue;
456             }
457         },
458         defaultValueCreator: (bindable) =>
459         {
460             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
461             return instance.InternalWrapModeV;
462         });
463
464         /// <summary>
465         /// AdjustViewSizeProperty
466         /// </summary>
467         [EditorBrowsable(EditorBrowsableState.Never)]
468         public static readonly BindableProperty AdjustViewSizeProperty = BindableProperty.Create(nameof(AdjustViewSize), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
469         {
470             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
471             if (newValue != null)
472             {
473                 instance.adjustViewSize = (bool)newValue;
474             }
475         },
476         defaultValueCreator: (bindable) =>
477         {
478             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
479             return instance.adjustViewSize;
480         });
481     }
482 }