f465547158f6bd85ce3c32d96cfa022231cc478a
[platform/core/csapi/tizenfx.git] / src / ElmSharp.Wearable / ElmSharp.Wearable / CircleGenList.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     /// The Circle GenList Selector is a widget to display and handle genlist items by rotary event
25     /// Inherits <see cref="GenList"/>
26     /// </summary>
27     public class CircleGenList : GenList, IRotaryActionWidget
28     {
29         IntPtr _circleHandle;
30         CircleSurface _surface;
31
32         /// <summary>
33         /// Creates and initializes a new instance of the Circle GenList class
34         /// </summary>
35         /// <param name="parent">The parent of new Circle GenList instance</param>
36         /// <param name="surface">The surface for drawing circle features for this widget.</param>
37         public CircleGenList(EvasObject parent, CircleSurface surface) : base()
38         {
39             Debug.Assert(parent == null || surface == null || parent.IsRealized);
40             _surface = surface;
41             Realize(parent);
42         }
43
44         /// <summary>
45         /// Creates and initializes a new instance of the Circle GenList class.
46         /// </summary>
47         /// <param name="parent">The parent of new Circle CircleGenList instance</param>
48         [Obsolete("It is not safe for guess circle surface from parent and create new surface by every new widget")]
49         [EditorBrowsable(EditorBrowsableState.Never)]
50         public CircleGenList(EvasObject parent) : this(parent, CircleSurface.CreateCircleSurface(parent))
51         {
52             ((IRotaryActionWidget)this).Activate();
53         }
54
55         /// <summary>
56         /// Gets the handle for Circle Widget.
57         /// </summary>
58         public virtual IntPtr CircleHandle => _circleHandle;
59
60         /// <summary>
61         /// Gets the handle for Circle Surface used in this widget
62         /// </summary>
63         public virtual CircleSurface CircleSurface => _surface;
64
65         /// <summary>
66         /// Sets or gets disabled state of this widget.
67         /// </summary>
68         [Obsolete("Use IsEnabled")]
69         [EditorBrowsable(EditorBrowsableState.Never)]
70         public bool Disabled
71         {
72             get => !IsEnabled;
73             set => IsEnabled = !value;
74         }
75
76         /// <summary>
77         /// Sets or gets the state of the widget, which might be enabled or disabled.
78         /// </summary>
79         public override bool IsEnabled
80         {
81             get
82             {
83                 return !Interop.Eext.eext_circle_object_disabled_get(CircleHandle);
84             }
85             set
86             {
87                 Interop.Eext.eext_circle_object_disabled_set(CircleHandle, !value);
88             }
89         }
90
91         /// <summary>
92         /// Sets or gets the color of the scroll background
93         /// </summary>
94         public Color VerticalScrollBackgroundColor
95         {
96             get
97             {
98                 int r, g, b, a;
99                 Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "vertical,scroll,bg", out r, out g, out b, out a);
100                 return new Color(r, g, b, a);
101             }
102             set
103             {
104                 Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "vertical,scroll,bg", value.R, value.G, value.B, value.A);
105             }
106         }
107
108         /// <summary>
109         /// Sets or gets the line width of the scroll background
110         /// </summary>
111         public int VerticalScrollBackgroundLineWidth
112         {
113             get
114             {
115                 return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "vertical,scroll,bg");
116             }
117             set
118             {
119                 Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "vertical,scroll,bg", value);
120             }
121         }
122
123         /// <summary>
124         /// Sets or gets the redius of the scroll background
125         /// </summary>
126         public double VerticalScrollBackgroundRadius
127         {
128             get
129             {
130                 return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "vertical,scroll,bg");
131             }
132             set
133             {
134                 Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "vertical,scroll,bg", value);
135             }
136         }
137
138         /// <summary>
139         /// Sets or gets the color of the scroll bar
140         /// </summary>
141         public Color VerticalScrollBarColor
142         {
143             get
144             {
145                 int r, g, b, a;
146                 Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "default", out r, out g, out b, out a);
147                 return new Color(r, g, b, a);
148             }
149             set
150             {
151                 Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "default", value.R, value.G, value.B, value.A);
152             }
153         }
154
155         /// <summary>
156         /// Sets or gets the line width of the scroll bar
157         /// </summary>
158         public int VerticalScrollBarLineWidth
159         {
160             get
161             {
162                 return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "default");
163             }
164             set
165             {
166                 Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "default", value);
167             }
168         }
169
170         /// <summary>
171         /// Sets or gets the redius of the scroll bar
172         /// </summary>
173         public double VerticalScrollBarRadius
174         {
175             get
176             {
177                 return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "default");
178             }
179             set
180             {
181                 Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "default", value);
182             }
183         }
184
185         /// <summary>
186         /// Sets or gets the policy if the scroll bar is visible
187         /// </summary>
188         /// <remarks>
189         /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
190         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
191         /// </remarks>
192         public override ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
193         {
194             get
195             {
196                 int policy;
197                 Interop.Eext.eext_circle_object_genlist_scroller_policy_get(CircleHandle, IntPtr.Zero, out policy);
198                 return (ScrollBarVisiblePolicy)policy;
199             }
200             set
201             {
202                 base.VerticalScrollBarVisiblePolicy = value;
203                 int h;
204                 Interop.Eext.eext_circle_object_genlist_scroller_policy_get(CircleHandle, out h, IntPtr.Zero);
205                 Interop.Eext.eext_circle_object_genlist_scroller_policy_set(CircleHandle, (int)h, (int)value);
206             }
207         }
208
209         /// <summary>
210         /// Creates a widget handle.
211         /// </summary>
212         /// <param name="parent">Parent EvasObject</param>
213         /// <returns>Handle IntPtr</returns>
214         protected override IntPtr CreateHandle(EvasObject parent)
215         {
216             var handle = base.CreateHandle(parent);
217             _circleHandle = Interop.Eext.eext_circle_object_genlist_add(RealHandle == IntPtr.Zero ? Handle : RealHandle, CircleSurface.Handle);
218
219             return handle;
220         }
221     }
222 }