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