6818b75e05197e1687df51d5fb6bdae1a38ac3cf
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Style / ImageControlStyle.cs
1 /*
2  * Copyright(c) 2019 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 using System.Collections.Generic;
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.Components
23 {
24     /// <summary>
25     /// ImageControlStyle is a class which saves Button's ux data.
26     /// </summary>
27     /// <since_tizen> 6 </since_tizen>
28     /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
29     [EditorBrowsable(EditorBrowsableState.Never)]
30     public class ImageControlStyle : ControlStyle
31     {
32         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
33         [EditorBrowsable(EditorBrowsableState.Never)]
34         public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create("ImageControlResourceUrl", typeof(Selector<string>), typeof(ImageControlStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
35         {
36             var imageControlStyle = (ImageControlStyle)bindable;
37             if (null == imageControlStyle.resourceUrlSelector) imageControlStyle.resourceUrlSelector = new Selector<string>();
38             imageControlStyle.resourceUrlSelector.Clone(null == newValue ? new Selector<string>() : (Selector<string>)newValue);
39         },
40         defaultValueCreator: (bindable) =>
41         {
42             var imageControlStyle = (ImageControlStyle)bindable;
43             return imageControlStyle.resourceUrlSelector;
44         });
45         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
46         [EditorBrowsable(EditorBrowsableState.Never)]
47         public static readonly BindableProperty BorderProperty = BindableProperty.Create("ImageControlBorder", typeof(Selector<Rectangle>), typeof(ImageControlStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
48         {
49             var imageControlStyle = (ImageControlStyle)bindable;
50             if (null == imageControlStyle.borderSelector) imageControlStyle.borderSelector = new Selector<Rectangle>();
51             imageControlStyle.borderSelector.Clone((Selector<Rectangle>)newValue);
52         },
53         defaultValueCreator: (bindable) =>
54         {
55             var imageControlStyle = (ImageControlStyle)bindable;
56             return imageControlStyle.borderSelector;
57         });
58
59         private Selector<string> resourceUrlSelector;
60         private Selector<Rectangle> borderSelector;
61
62         static ImageControlStyle() { }
63
64         /// <summary>
65         /// Creates a new instance of a ImageControlStyle.
66         /// </summary>
67         /// <since_tizen> 6 </since_tizen>
68         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
69         [EditorBrowsable(EditorBrowsableState.Never)]
70         public ImageControlStyle() : base() { }
71
72         /// <summary>
73         /// Creates a new instance of a ImageControlStyle with style.
74         /// </summary>
75         /// <param name="style">Create ImageControlStyle by style customized by user.</param>
76         /// <since_tizen> 6 </since_tizen>
77         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
78         [EditorBrowsable(EditorBrowsableState.Never)]
79         public ImageControlStyle(ImageControlStyle style) : base(style)
80         {
81             if(null == style) return;
82
83             this.CopyFrom(style);
84         }
85
86         /// <summary>
87         /// Image URL.
88         /// </summary>
89         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
90         [EditorBrowsable(EditorBrowsableState.Never)]
91         public Selector<string> ResourceUrl
92         {
93             get
94             {
95                 Selector<string> url = (Selector<string>)GetValue(ResourceUrlProperty);
96                 return (null != url) ? url : resourceUrlSelector = new Selector<string>();
97             }
98             set => SetValue(ResourceUrlProperty, value);
99         }
100
101         /// <summary>
102         /// Image border.
103         /// </summary>
104         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public Selector<Rectangle> Border
107         {
108             get
109             {
110                 Selector<Rectangle> border = (Selector<Rectangle>)GetValue(BorderProperty);
111                 return (null != border) ? border : borderSelector = new Selector<Rectangle>();
112             }
113             set => SetValue(BorderProperty, value);
114         }
115
116         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
117         [EditorBrowsable(EditorBrowsableState.Never)]
118         public override void CopyFrom(BindableObject bindableObject)
119         {
120             base.CopyFrom(bindableObject);
121
122             ImageControlStyle imageControlStyle = bindableObject as ImageControlStyle;
123
124             if (null != imageControlStyle)
125             {
126                 if (null != imageControlStyle.ResourceUrl)
127                 {
128                     if (null == ResourceUrl) ResourceUrl = new Selector<string>();
129                     ResourceUrl.Clone(imageControlStyle.ResourceUrl);
130                 }
131                 if (null != imageControlStyle.Border)
132                 {
133                     if (null == Border) Border = new Selector<Rectangle>();
134                     Border.Clone(imageControlStyle.Border);
135                 }
136             }
137         }
138     }
139 }