[ElmSharp] Mark ElmSharp API as API Level: preview
[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 using System.ComponentModel;
19 using System.Diagnostics;
20
21 namespace ElmSharp.Wearable
22 {
23     /// <summary>
24     /// Circle scroller provides scrollbar with circular movement and is scrolled by rotary event.
25     /// </summary>
26     /// <since_tizen> preview </since_tizen>
27     public class CircleScroller : Scroller, IRotaryActionWidget
28     {
29         IntPtr _circleHandle;
30         CircleSurface _surface;
31
32         /// <summary>
33         /// Creates and initializes a new instance of the CircleScroller class.
34         /// </summary>
35         /// <param name="parent">The <see cref="EvasObject"/> to which the new CircleScroller will be attached as a child.</param>
36         /// <param name="surface">The surface for drawing circle features for this widget.</param>
37         /// <since_tizen> preview </since_tizen>
38         public CircleScroller(EvasObject parent, CircleSurface surface) : base()
39         {
40             Debug.Assert(parent == null || surface == null || parent.IsRealized);
41             _surface = surface;
42             Realize(parent);
43         }
44
45         /// <summary>
46         /// Creates and initializes a new instance of the Circle Scroller class.
47         /// </summary>
48         /// <param name="parent">The parent of new Circle CircleScroller instance</param>
49         /// <since_tizen> preview </since_tizen>
50         [Obsolete("It is not safe for guess circle surface from parent and create new surface by every new widget")]
51         [EditorBrowsable(EditorBrowsableState.Never)]
52         public CircleScroller(EvasObject parent) : this(parent, CircleSurface.CreateCircleSurface(parent))
53         {
54             ((IRotaryActionWidget)this).Activate();
55         }
56
57         /// <summary>
58         /// Gets the handle for Circle Widget.
59         /// </summary>
60         /// <since_tizen> preview </since_tizen>
61         public virtual IntPtr CircleHandle => _circleHandle;
62
63         /// <summary>
64         /// Gets the handle for Circle Surface used in this widget
65         /// </summary>
66         /// <since_tizen> preview </since_tizen>
67         public virtual CircleSurface CircleSurface => _surface;
68
69         /// <summary>
70         /// Sets or gets disabled state of this widget.
71         /// </summary>
72         /// <since_tizen> preview </since_tizen>
73         [Obsolete("Use IsEnabled")]
74         [EditorBrowsable(EditorBrowsableState.Never)]
75         public bool Disabled
76         {
77             get => !IsEnabled;
78             set => IsEnabled = !value;
79         }
80
81         /// <summary>
82         /// Sets or gets the state of the widget, which might be enabled or disabled.
83         /// </summary>
84         /// <since_tizen> preview </since_tizen>
85         public override bool IsEnabled
86         {
87             get
88             {
89                 return !Interop.Eext.eext_circle_object_disabled_get(CircleHandle);
90             }
91             set
92             {
93                 Interop.Eext.eext_circle_object_disabled_set(CircleHandle, !value);
94             }
95         }
96
97         /// <summary>
98         /// Sets or gets the value of HorizontalScrollBarVisiblePolicy
99         /// </summary>
100         /// <remarks>
101         /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
102         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
103         /// </remarks>
104         /// <since_tizen> preview </since_tizen>
105         public override ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
106         {
107             get
108             {
109                 int policy;
110                 Interop.Eext.eext_circle_object_scroller_policy_get(CircleHandle, out policy, IntPtr.Zero);
111                 return (ScrollBarVisiblePolicy)policy;
112             }
113             set
114             {
115                 ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
116                 Interop.Eext.eext_circle_object_scroller_policy_set(CircleHandle, (int)value, (int)v);
117             }
118         }
119
120         /// <summary>
121         /// Sets or gets the value of VerticalScrollBarVisiblePolicy
122         /// </summary>
123         /// <remarks>
124         /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
125         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
126         /// </remarks>
127         /// <since_tizen> preview </since_tizen>
128         public override ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
129         {
130             get
131             {
132                 int policy;
133                 Interop.Eext.eext_circle_object_scroller_policy_get(CircleHandle, IntPtr.Zero, out policy);
134                 return (ScrollBarVisiblePolicy)policy;
135             }
136             set
137             {
138                 ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
139                 Interop.Eext.eext_circle_object_scroller_policy_set(CircleHandle, (int)h, (int)value);
140             }
141         }
142
143         /// <summary>
144         /// Sets or gets color of the vertical scroll bar.
145         /// </summary>
146         /// <since_tizen> preview </since_tizen>
147         public Color VerticalScrollBarColor
148         {
149             get
150             {
151                 int r = 0;
152                 int g = 0;
153                 int b = 0;
154                 int a = 0;
155                 Interop.Eext.eext_circle_object_color_get(CircleHandle, out r, out g, out b, out a);
156                 return Color.FromRgba(r, g, b, a);
157             }
158             set
159             {
160                 Interop.Eext.eext_circle_object_color_set(CircleHandle, value.R, value.G, value.B, value.A);
161             }
162         }
163
164         /// <summary>
165         /// Sets or gets color of the horizontal scroll bar.
166         /// </summary>
167         /// <since_tizen> preview </since_tizen>
168         public Color HorizontalScrollBarColor
169         {
170             get
171             {
172                 int r = 0;
173                 int g = 0;
174                 int b = 0;
175                 int a = 0;
176                 Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "horizontal,scroll,bar", out r, out g, out b, out a);
177                 return Color.FromRgba(r, g, b, a);
178             }
179             set
180             {
181                 Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "horizontal,scroll,bar", value.R, value.G, value.B, value.A);
182             }
183         }
184
185         /// <summary>
186         /// Sets or gets color of the vertical scroll background.
187         /// </summary>
188         /// <since_tizen> preview </since_tizen>
189         public Color VerticalScrollBackgroundColor
190         {
191             get
192             {
193                 int r = 0;
194                 int g = 0;
195                 int b = 0;
196                 int a = 0;
197                 Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "vertical,scroll,bg", out r, out g, out b, out a);
198                 return Color.FromRgba(r, g, b, a);
199             }
200             set
201             {
202                 Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "vertical,scroll,bg", value.R, value.G, value.B, value.A);
203             }
204         }
205
206         /// <summary>
207         /// Sets or gets color of the horizontal scroll background.
208         /// </summary>
209         /// <since_tizen> preview </since_tizen>
210         public Color HorizontalScrollBackgroundColor
211         {
212             get
213             {
214                 int r = 0;
215                 int g = 0;
216                 int b = 0;
217                 int a = 0;
218                 Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "horizontal,scroll,bg", out r, out g, out b, out a);
219                 return Color.FromRgba(r, g, b, a);
220             }
221             set
222             {
223                 Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "horizontal,scroll,bg", value.R, value.G, value.B, value.A);
224             }
225         }
226
227         /// <summary>
228         /// Sets or gets line width of the vertical scroll bar.
229         /// </summary>
230         /// <since_tizen> preview </since_tizen>
231         public int VerticalScrollBarLineWidth
232         {
233             get
234             {
235                 return Interop.Eext.eext_circle_object_line_width_get(CircleHandle);
236             }
237             set
238             {
239                 Interop.Eext.eext_circle_object_line_width_set(CircleHandle, value);
240             }
241         }
242
243         /// <summary>
244         /// Sets or gets line width of the horizontal scroll bar.
245         /// </summary>
246         /// <since_tizen> preview </since_tizen>
247         public int HorizontalScrollBarLineWidth
248         {
249             get
250             {
251                 return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "horizontal,scroll,bar");
252             }
253             set
254             {
255                 Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "horizontal,scroll,bar", value);
256             }
257         }
258
259         /// <summary>
260         /// Sets or gets line width of the vertical scroll background.
261         /// </summary>
262         /// <since_tizen> preview </since_tizen>
263         public int VerticalScrollBackgroundLineWidth
264         {
265             get
266             {
267                 return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "vertical,scroll,bg");
268             }
269             set
270             {
271                 Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "vertical,scroll,bg", value);
272             }
273         }
274
275         /// <summary>
276         /// Sets or gets line width of the horizontal scroll background.
277         /// </summary>
278         /// <since_tizen> preview </since_tizen>
279         public int HorizontalScrollBackgroundLineWidth
280         {
281             get
282             {
283                 return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "horizontal,scroll,bg");
284             }
285             set
286             {
287                 Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "horizontal,scroll,bg", value);
288             }
289         }
290
291         /// <summary>
292         /// Sets or gets radius of the vertical scroll bar.
293         /// </summary>
294         /// <since_tizen> preview </since_tizen>
295         public double VerticalScrollBarRadius
296         {
297             get
298             {
299                 return Interop.Eext.eext_circle_object_radius_get(CircleHandle);
300             }
301             set
302             {
303                 Interop.Eext.eext_circle_object_radius_set(CircleHandle, value);
304             }
305         }
306
307         /// <summary>
308         /// Sets or gets radius of the horizontal scroll bar.
309         /// </summary>
310         /// <since_tizen> preview </since_tizen>
311         public double HorizontalScrollBarRadius
312         {
313             get
314             {
315                 return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "horizontal,scroll,bar");
316             }
317             set
318             {
319                 Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "horizontal,scroll,bar", value);
320             }
321         }
322
323         /// <summary>
324         /// Sets or gets radius of the vertical scroll background.
325         /// </summary>
326         /// <since_tizen> preview </since_tizen>
327         public double VerticalScrollBackgroundRadius
328         {
329             get
330             {
331                 return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "vertical,scroll,bg");
332             }
333             set
334             {
335                 Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "vertical,scroll,bg", value);
336             }
337         }
338
339         /// <summary>
340         /// Sets or gets radius of the horizontal scroll background.
341         /// </summary>
342         /// <since_tizen> preview </since_tizen>
343         public double HorizontalScrollBackgroundRadius
344         {
345             get
346             {
347                 return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "horizontal,scroll,bg");
348             }
349             set
350             {
351                 Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "horizontal,scroll,bg", value);
352             }
353         }
354
355         /// <summary>
356         /// Creates a widget handle.
357         /// </summary>
358         /// <param name="parent">Parent EvasObject</param>
359         /// <returns>Handle IntPtr</returns>
360         /// <since_tizen> preview </since_tizen>
361         protected override IntPtr CreateHandle(EvasObject parent)
362         {
363             IntPtr handle = base.CreateHandle(parent);
364             _circleHandle = Interop.Eext.eext_circle_object_scroller_add(RealHandle == IntPtr.Zero ? handle : RealHandle, CircleSurface.Handle);
365             return handle;
366         }
367     }
368 }