[NUI] Support dp converter for Width/Height specification (#3601)
[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             PropertyMap imageMap = new PropertyMap();
48             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
49             imageMap.Find(ImageVisualProperty.URL)?.Get(out ret);
50             return ret;
51         }));
52
53         /// Intenal used, will never be opened.
54         [EditorBrowsable(EditorBrowsableState.Never)]
55         public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(ImageView.Image), typeof(PropertyMap), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
56         {
57             var imageView = (ImageView)bindable;
58             if (newValue != null)
59             {
60                 PropertyMap map = (PropertyMap)newValue;
61                 if (imageView.IsCreateByXaml)
62                 {
63                     string url = "", alphaMaskURL = "", auxiliaryImageURL = "";
64                     string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
65                     PropertyValue urlValue = map.Find(NDalic.ImageVisualUrl);
66                     bool ret = false;
67                     if (urlValue != null) ret = urlValue.Get(out url);
68                     PropertyMap mmap = new PropertyMap();
69                     if (ret && url.StartsWith("*Resource*"))
70                     {
71                         url = url.Replace("*Resource*", resource);
72                         mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(url));
73                     }
74
75                     ret = false;
76                     PropertyValue alphaMaskUrlValue = map.Find(NDalic.ImageVisualAlphaMaskUrl);
77                     if (alphaMaskUrlValue != null) ret = alphaMaskUrlValue.Get(out alphaMaskURL);
78                     if (ret && alphaMaskURL.StartsWith("*Resource*"))
79                     {
80                         alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource);
81                         mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(alphaMaskURL));
82                     }
83
84                     ret = false;
85                     PropertyValue auxiliaryImageURLValue = map.Find(NDalic.ImageVisualAuxiliaryImageUrl);
86                     if (auxiliaryImageURLValue != null) ret = auxiliaryImageURLValue.Get(out auxiliaryImageURL);
87                     if (ret && auxiliaryImageURL.StartsWith("*Resource*"))
88                     {
89                         auxiliaryImageURL = auxiliaryImageURL.Replace("*Resource*", resource);
90                         mmap.Insert(NDalic.ImageVisualAuxiliaryImageUrl, new PropertyValue(auxiliaryImageURL));
91                     }
92
93                     map.Merge(mmap);
94                 }
95                 if (imageView._border == null)
96                 {
97                     Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
98                 }
99             }
100         }),
101         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
102         {
103             var imageView = (ImageView)bindable;
104             if (imageView._border == null)
105             {
106                 PropertyMap temp = new PropertyMap();
107                 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(temp);
108                 return temp;
109             }
110             else
111             {
112                 return null;
113             }
114         }));
115
116         /// Intenal used, will never be opened.
117         [EditorBrowsable(EditorBrowsableState.Never)]
118         public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create(nameof(PreMultipliedAlpha), typeof(bool), typeof(ImageView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
119         {
120             var imageView = (ImageView)bindable;
121             if (newValue != null)
122             {
123                 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, new Tizen.NUI.PropertyValue((bool)newValue));
124             }
125         }),
126         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
127         {
128             var imageView = (ImageView)bindable;
129             bool temp = false;
130             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha).Get(out temp);
131             return temp;
132         }));
133
134         /// Intenal used, will never be opened.
135         [EditorBrowsable(EditorBrowsableState.Never)]
136         public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
137         {
138             var imageView = (ImageView)bindable;
139             if (newValue != null)
140             {
141                 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
142             }
143         }),
144         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
145         {
146             var imageView = (ImageView)bindable;
147             Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
148             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea).Get(temp);
149             RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
150             return relativeTemp;
151         }));
152
153         /// Intenal used, will never be opened.
154         [EditorBrowsable(EditorBrowsableState.Never)]
155         public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
156         {
157             var imageView = (ImageView)bindable;
158             imageView.borderSelector?.Reset(imageView);
159
160             if (newValue is Selector<Rectangle> selector)
161             {
162                 if (selector.HasAll()) imageView.SetBorder(selector.All);
163                 else imageView.borderSelector = new TriggerableSelector<Rectangle>(imageView, selector, imageView.SetBorder, true);
164             }
165             else
166             {
167                 imageView.SetBorder((Rectangle)newValue);
168             }
169         },
170         defaultValueCreator: (bindable) =>
171         {
172             var imageView = (ImageView)bindable;
173             return imageView._border;
174         });
175
176         /// Intenal used, will never be opened.
177         [EditorBrowsable(EditorBrowsableState.Never)]
178         public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
179         {
180             var imageView = (ImageView)bindable;
181             if (newValue != null)
182             {
183                 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
184             }
185         },
186         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
187         {
188             var imageView = (ImageView)bindable;
189             bool ret = false;
190             PropertyMap imageMap = new PropertyMap();
191             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
192             imageMap.Find(ImageVisualProperty.BorderOnly)?.Get(out ret);
193             return ret;
194         }));
195
196         /// Intenal used, will never be opened.
197         [EditorBrowsable(EditorBrowsableState.Never)]
198         public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
199         {
200             var imageView = (ImageView)bindable;
201             if (newValue != null)
202             {
203                 imageView._synchronousLoading = (bool)newValue;
204                 imageView.UpdateImage(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
205             }
206         },
207         defaultValueCreator: (bindable) =>
208         {
209             var imageView = (ImageView)bindable;
210             return imageView._synchronousLoading;
211         });
212
213         /// This will be public opened in tizen_7.0 after ACR done. Before ACR, need to be hidden as inhouse API.
214         [EditorBrowsable(EditorBrowsableState.Never)]
215         public static readonly BindableProperty SynchronousLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
216         {
217             var imageView = (ImageView)bindable;
218             if (newValue != null)
219             {
220                 imageView._synchronousLoading = (bool)newValue;
221                 imageView.UpdateImage(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
222             }
223         },
224         defaultValueCreator: (bindable) =>
225         {
226             var imageView = (ImageView)bindable;
227             return imageView._synchronousLoading;
228         });
229
230         /// Intenal used, will never be opened.
231         [EditorBrowsable(EditorBrowsableState.Never)]
232         public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
233         {
234             var imageView = (ImageView)bindable;
235             if (newValue != null)
236             {
237                 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
238             }
239         },
240         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
241         {
242             var imageView = (ImageView)bindable;
243
244             bool ret = false;
245             PropertyMap imageMap = new PropertyMap();
246             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
247             imageMap?.Find(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
248
249             return ret;
250         }));
251
252         /// <summary>
253         /// ImageMapProperty
254         /// </summary>
255         [EditorBrowsable(EditorBrowsableState.Never)]
256         public static readonly BindableProperty ImageMapProperty = BindableProperty.Create(nameof(ImageMap), typeof(Tizen.NUI.PropertyMap), typeof(Tizen.NUI.BaseComponents.ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
257         {
258             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
259             if (newValue != null)
260             {
261                 instance.InternalImageMap = (Tizen.NUI.PropertyMap)newValue;
262             }
263         },
264         defaultValueCreator: (bindable) =>
265         {
266             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
267             return instance.InternalImageMap;
268         });
269
270         /// <summary>
271         /// AlphaMaskURLProperty
272         /// </summary>
273         [EditorBrowsable(EditorBrowsableState.Never)]
274         public static readonly BindableProperty AlphaMaskURLProperty = BindableProperty.Create(nameof(AlphaMaskURL), typeof(string), typeof(Tizen.NUI.BaseComponents.ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
275         {
276             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
277             if (newValue != null)
278             {
279                 instance.InternalAlphaMaskURL = (string)newValue;
280             }
281         },
282         defaultValueCreator: (bindable) =>
283         {
284             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
285             return instance.InternalAlphaMaskURL;
286         });
287
288         /// <summary>
289         /// CropToMaskProperty
290         /// </summary>
291         [EditorBrowsable(EditorBrowsableState.Never)]
292         public static readonly BindableProperty CropToMaskProperty = BindableProperty.Create(nameof(CropToMask), typeof(bool), typeof(Tizen.NUI.BaseComponents.ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
293         {
294             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
295             if (newValue != null)
296             {
297                 instance.InternalCropToMask = (bool)newValue;
298             }
299         },
300         defaultValueCreator: (bindable) =>
301         {
302             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
303             return instance.InternalCropToMask;
304         });
305
306         /// <summary>
307         /// FittingModeProperty
308         /// </summary>
309         [EditorBrowsable(EditorBrowsableState.Never)]
310         public static readonly BindableProperty FittingModeProperty = BindableProperty.Create(nameof(FittingMode), typeof(Tizen.NUI.FittingModeType), typeof(Tizen.NUI.BaseComponents.ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
311         {
312             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
313             if (newValue != null)
314             {
315                 instance.InternalFittingMode = (Tizen.NUI.FittingModeType)newValue;
316             }
317         },
318         defaultValueCreator: (bindable) =>
319         {
320             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
321             return instance.InternalFittingMode;
322         });
323
324         /// <summary>
325         /// DesiredWidthProperty
326         /// </summary>
327         [EditorBrowsable(EditorBrowsableState.Never)]
328         public static readonly BindableProperty DesiredWidthProperty = BindableProperty.Create(nameof(DesiredWidth), typeof(int), typeof(Tizen.NUI.BaseComponents.ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
329         {
330             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
331             if (newValue != null)
332             {
333                 instance.InternalDesiredWidth = (int)newValue;
334             }
335         },
336         defaultValueCreator: (bindable) =>
337         {
338             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
339             return instance.InternalDesiredWidth;
340         });
341
342         /// <summary>
343         /// DesiredHeightProperty
344         /// </summary>
345         [EditorBrowsable(EditorBrowsableState.Never)]
346         public static readonly BindableProperty DesiredHeightProperty = BindableProperty.Create(nameof(DesiredHeight), typeof(int), typeof(Tizen.NUI.BaseComponents.ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
347         {
348             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
349             if (newValue != null)
350             {
351                 instance.InternalDesiredHeight = (int)newValue;
352             }
353         },
354         defaultValueCreator: (bindable) =>
355         {
356             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
357             return instance.InternalDesiredHeight;
358         });
359
360         /// <summary>
361         /// ReleasePolicyProperty
362         /// </summary>
363         [EditorBrowsable(EditorBrowsableState.Never)]
364         public static readonly BindableProperty ReleasePolicyProperty = BindableProperty.Create(nameof(ReleasePolicy), typeof(Tizen.NUI.ReleasePolicyType), typeof(Tizen.NUI.BaseComponents.ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
365         {
366             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
367             if (newValue != null)
368             {
369                 instance.InternalReleasePolicy = (Tizen.NUI.ReleasePolicyType)newValue;
370             }
371         },
372         defaultValueCreator: (bindable) =>
373         {
374             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
375             return instance.InternalReleasePolicy;
376         });
377
378         /// <summary>
379         /// WrapModeUProperty
380         /// </summary>
381         [EditorBrowsable(EditorBrowsableState.Never)]
382         public static readonly BindableProperty WrapModeUProperty = BindableProperty.Create(nameof(WrapModeU), typeof(Tizen.NUI.WrapModeType), typeof(Tizen.NUI.BaseComponents.ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
383         {
384             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
385             if (newValue != null)
386             {
387                 instance.InternalWrapModeU = (Tizen.NUI.WrapModeType)newValue;
388             }
389         },
390         defaultValueCreator: (bindable) =>
391         {
392             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
393             return instance.InternalWrapModeU;
394         });
395
396         /// <summary>
397         /// WrapModeVProperty
398         /// </summary>
399         [EditorBrowsable(EditorBrowsableState.Never)]
400         public static readonly BindableProperty WrapModeVProperty = BindableProperty.Create(nameof(WrapModeV), typeof(Tizen.NUI.WrapModeType), typeof(Tizen.NUI.BaseComponents.ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
401         {
402             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
403             if (newValue != null)
404             {
405                 instance.InternalWrapModeV = (Tizen.NUI.WrapModeType)newValue;
406             }
407         },
408         defaultValueCreator: (bindable) =>
409         {
410             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
411             return instance.InternalWrapModeV;
412         });
413
414         /// <summary>
415         /// AdjustViewSizeProperty
416         /// </summary>
417         [EditorBrowsable(EditorBrowsableState.Never)]
418         public static readonly BindableProperty AdjustViewSizeProperty = BindableProperty.Create(nameof(AdjustViewSize), typeof(bool), typeof(Tizen.NUI.BaseComponents.ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
419         {
420             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
421             if (newValue != null)
422             {
423                 instance.adjustViewSize = (bool)newValue;
424             }
425         },
426         defaultValueCreator: (bindable) =>
427         {
428             var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
429             return instance.adjustViewSize;
430         });
431     }
432 }