Release 4.0.0-preview1-00285
[platform/core/csapi/tizenfx.git] / src / ElmSharp.Wearable / ElmSharp.Wearable / CircleScroller.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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;
18
19 namespace ElmSharp.Wearable
20 {
21     /// <summary>
22     /// Circle scroller provides scrollbar with circular movement and is scrolled by rotary event.
23     /// </summary>
24     public class CircleScroller : Scroller
25     {
26         private IntPtr _circleHandle;
27
28         /// <summary>
29         /// Creates and initializes a new instance of the CircleScroller class.
30         /// </summary>
31         /// <param name="parent">The <see cref="EvasObject"/> to which the new CircleScroller will be attached as a child.</param>
32         public CircleScroller(EvasObject parent) : base(parent)
33         {
34         }
35
36         /// <summary>
37         /// Sets or gets disabled state of the circle scroller object.
38         /// </summary>
39         public bool Disabled
40         {
41             get
42             {
43                 return Interop.Eext.eext_circle_object_disabled_get(_circleHandle); ;
44             }
45             set
46             {
47                 Interop.Eext.eext_circle_object_disabled_set(_circleHandle, value);
48             }
49         }
50
51         /// <summary>
52         /// Sets or gets the value of HorizontalScrollBarVisiblePolicy
53         /// </summary>
54         /// <remarks>
55         /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
56         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
57         /// </remarks>
58         public override ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
59         {
60             get
61             {
62                 int policy;
63                 Interop.Eext.eext_circle_object_scroller_policy_get(_circleHandle, out policy, IntPtr.Zero);
64                 return (ScrollBarVisiblePolicy)policy;
65             }
66             set
67             {
68                 ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
69                 Interop.Eext.eext_circle_object_scroller_policy_set(_circleHandle, (int)value, (int)v);
70             }
71         }
72
73         /// <summary>
74         /// Sets or gets the value of VerticalScrollBarVisiblePolicy
75         /// </summary>
76         /// <remarks>
77         /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
78         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
79         /// </remarks>
80         public override ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
81         {
82             get
83             {
84                 int policy;
85                 Interop.Eext.eext_circle_object_scroller_policy_get(_circleHandle, IntPtr.Zero, out policy);
86                 return (ScrollBarVisiblePolicy)policy;
87             }
88             set
89             {
90                 ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
91                 Interop.Eext.eext_circle_object_scroller_policy_set(_circleHandle, (int)h, (int)value);
92             }
93         }
94
95         /// <summary>
96         /// Sets or gets color of the vertical scroll bar.
97         /// </summary>
98         public Color VerticalScrollBarColor
99         {
100             get
101             {
102                 int r = 0;
103                 int g = 0;
104                 int b = 0;
105                 int a = 0;
106                 Interop.Eext.eext_circle_object_color_get(_circleHandle, out r, out g, out b, out a);
107                 return Color.FromRgba(r, g, b, a);
108             }
109             set
110             {
111                 Interop.Eext.eext_circle_object_color_set(_circleHandle, value.R, value.G, value.B, value.A);
112             }
113         }
114
115         /// <summary>
116         /// Sets or gets color of the horizontal scroll bar.
117         /// </summary>
118         public Color HorizontalScrollBarColor
119         {
120             get
121             {
122                 int r = 0;
123                 int g = 0;
124                 int b = 0;
125                 int a = 0;
126                 Interop.Eext.eext_circle_object_item_color_get(_circleHandle, "horizontal,scroll,bar", out r, out g, out b, out a);
127                 return Color.FromRgba(r, g, b, a);
128             }
129             set
130             {
131                 Interop.Eext.eext_circle_object_item_color_set(_circleHandle, "horizontal,scroll,bar", value.R, value.G, value.B, value.A);
132             }
133         }
134
135         /// <summary>
136         /// Sets or gets color of the vertical scroll background.
137         /// </summary>
138         public Color VerticalScrollBackgroundColor
139         {
140             get
141             {
142                 int r = 0;
143                 int g = 0;
144                 int b = 0;
145                 int a = 0;
146                 Interop.Eext.eext_circle_object_item_color_get(_circleHandle, "vertical,scroll,bg", out r, out g, out b, out a);
147                 return Color.FromRgba(r, g, b, a);
148             }
149             set
150             {
151                 Interop.Eext.eext_circle_object_item_color_set(_circleHandle, "vertical,scroll,bg", value.R, value.G, value.B, value.A);
152             }
153         }
154
155         /// <summary>
156         /// Sets or gets color of the horizontal scroll background.
157         /// </summary>
158         public Color HorizontalScrollBackgroundColor
159         {
160             get
161             {
162                 int r = 0;
163                 int g = 0;
164                 int b = 0;
165                 int a = 0;
166                 Interop.Eext.eext_circle_object_item_color_get(_circleHandle, "horizontal,scroll,bg", out r, out g, out b, out a);
167                 return Color.FromRgba(r, g, b, a);
168             }
169             set
170             {
171                 Interop.Eext.eext_circle_object_item_color_set(_circleHandle, "horizontal,scroll,bg", value.R, value.G, value.B, value.A);
172             }
173         }
174
175         /// <summary>
176         /// Sets or gets line width of the vertical scroll bar.
177         /// </summary>
178         public int VerticalScrollBarLineWidth
179         {
180             get
181             {
182                 return Interop.Eext.eext_circle_object_line_width_get(_circleHandle); ;
183             }
184             set
185             {
186                 Interop.Eext.eext_circle_object_line_width_set(_circleHandle, value);
187             }
188         }
189
190         /// <summary>
191         /// Sets or gets line width of the horizontal scroll bar.
192         /// </summary>
193         public int HorizontalScrollBarLineWidth
194         {
195             get
196             {
197                 return Interop.Eext.eext_circle_object_item_line_width_get(_circleHandle, "horizontal,scroll,bar");
198             }
199             set
200             {
201                 Interop.Eext.eext_circle_object_item_line_width_set(_circleHandle, "horizontal,scroll,bar", value);
202             }
203         }
204
205         /// <summary>
206         /// Sets or gets line width of the vertical scroll background.
207         /// </summary>
208         public int VerticalScrollBackgroundLineWidth
209         {
210             get
211             {
212                 return Interop.Eext.eext_circle_object_item_line_width_get(_circleHandle, "vertical,scroll,bg");
213             }
214             set
215             {
216                 Interop.Eext.eext_circle_object_item_line_width_set(_circleHandle, "vertical,scroll,bg", value);
217             }
218         }
219
220         /// <summary>
221         /// Sets or gets line width of the horizontal scroll background.
222         /// </summary>
223         public int HorizontalScrollBackgroundLineWidth
224         {
225             get
226             {
227                 return Interop.Eext.eext_circle_object_item_line_width_get(_circleHandle, "horizontal,scroll,bg");
228             }
229             set
230             {
231                 Interop.Eext.eext_circle_object_item_line_width_set(_circleHandle, "horizontal,scroll,bg", value);
232             }
233         }
234
235         /// <summary>
236         /// Sets or gets radius of the vertical scroll bar.
237         /// </summary>
238         public double VerticalScrollBarRadius
239         {
240             get
241             {
242                 return Interop.Eext.eext_circle_object_radius_get(_circleHandle); ;
243             }
244             set
245             {
246                 Interop.Eext.eext_circle_object_radius_set(_circleHandle, value);
247             }
248         }
249
250         /// <summary>
251         /// Sets or gets radius of the horizontal scroll bar.
252         /// </summary>
253         public double HorizontalScrollBarRadius
254         {
255             get
256             {
257                 return Interop.Eext.eext_circle_object_item_radius_get(_circleHandle, "horizontal,scroll,bar"); ;
258             }
259             set
260             {
261                 Interop.Eext.eext_circle_object_item_radius_set(_circleHandle, "horizontal,scroll,bar", value);
262             }
263         }
264
265         /// <summary>
266         /// Sets or gets radius of the vertical scroll background.
267         /// </summary>
268         public double VerticalScrollBackgroundRadius
269         {
270             get
271             {
272                 return Interop.Eext.eext_circle_object_item_radius_get(_circleHandle, "vertical,scroll,bg"); ;
273             }
274             set
275             {
276                 Interop.Eext.eext_circle_object_item_radius_set(_circleHandle, "vertical,scroll,bg", value);
277             }
278         }
279
280         /// <summary>
281         /// Sets or gets radius of the horizontal scroll background.
282         /// </summary>
283         public double HorizontalScrollBackgroundRadius
284         {
285             get
286             {
287                 return Interop.Eext.eext_circle_object_item_radius_get(_circleHandle, "horizontal,scroll,bg"); ;
288             }
289             set
290             {
291                 Interop.Eext.eext_circle_object_item_radius_set(_circleHandle, "horizontal,scroll,bg", value);
292             }
293         }
294
295         /// <summary>
296         /// Creates a widget handle.
297         /// </summary>
298         /// <param name="parent">Parent EvasObject</param>
299         /// <returns>Handle IntPtr</returns>
300         protected override IntPtr CreateHandle(EvasObject parent)
301         {
302             IntPtr handle = base.CreateHandle(parent);
303             IntPtr surface = IntPtr.Zero;
304             if (parent is Conformant)
305             {
306                 surface = Interop.Eext.eext_circle_surface_conformant_add(parent);
307             }
308             else if (parent is Layout)
309             {
310                 surface = Interop.Eext.eext_circle_surface_layout_add(parent);
311             }
312             else if (parent is Naviframe)
313             {
314                 surface = Interop.Eext.eext_circle_surface_naviframe_add(parent.RealHandle);
315             }
316
317             _circleHandle = Interop.Eext.eext_circle_object_scroller_add(RealHandle, surface);
318             if (surface == IntPtr.Zero)
319             {
320                 EvasObject p = parent;
321                 while (!(p is Window))
322                 {
323                     p = p.Parent;
324                 }
325                 var w = (p as Window).ScreenSize.Width;
326                 var h = (p as Window).ScreenSize.Height;
327                 Interop.Evas.evas_object_resize(_circleHandle, w, h);
328             }
329             Interop.Eext.eext_rotary_object_event_activated_set(_circleHandle, true);
330             return handle;
331         }
332     }
333 }