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