Merge "Add GenList TC for checking operation to remove GenListItem." into devel/dotnet
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Scroller.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
20 {
21     public enum ScrollBarVisiblePolicy
22     {
23         Auto = 0,
24         Visible,
25         Invisible
26     }
27
28     public enum ScrollBlock
29     {
30         None = 1,
31         Vertical = 2,
32         Horizontal = 4
33     }
34
35     public class Scroller : Layout
36     {
37         SmartEvent _scroll;
38         SmartEvent _dragStart;
39         SmartEvent _dragStop;
40         SmartEvent _scrollpage;
41
42         public Scroller(EvasObject parent) : base(parent)
43         {
44             _scroll = new SmartEvent(this, "scroll");
45             _dragStart = new SmartEvent(this, "scroll,drag,start");
46             _dragStop = new SmartEvent(this, "scroll,drag,stop");
47             _scrollpage = new SmartEvent(this, "scroll,page,changed");
48         }
49
50         public event EventHandler Scrolled
51         {
52             add
53             {
54                 _scroll.On += value;
55             }
56             remove
57             {
58                 _scroll.On -= value;
59             }
60         }
61         public event EventHandler DragStart
62         {
63             add
64             {
65                 _dragStart.On += value;
66             }
67             remove
68             {
69                 _dragStart.On -= value;
70             }
71         }
72         public event EventHandler DragStop
73         {
74             add
75             {
76                 _dragStop.On += value;
77             }
78             remove
79             {
80                 _dragStop.On -= value;
81             }
82         }
83         public event EventHandler PageScrolled
84         {
85             add
86             {
87                 _scrollpage.On += value;
88             }
89             remove
90             {
91                 _scrollpage.On -= value;
92             }
93         }
94
95         public Rect CurrentRegion
96         {
97             get
98             {
99                 int x, y, w, h;
100                 Interop.Elementary.elm_scroller_region_get(Handle, out x, out y, out w, out h);
101                 return new Rect(x, y, w, h);
102             }
103         }
104
105         public ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
106         {
107             get
108             {
109                 int policy;
110                 Interop.Elementary.elm_scroller_policy_get(Handle, out policy, IntPtr.Zero);
111                 return (ScrollBarVisiblePolicy)policy;
112             }
113             set
114             {
115                 ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
116                 Interop.Elementary.elm_scroller_policy_set(Handle, (int)value, (int)v);
117             }
118         }
119
120         public ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
121         {
122             get
123             {
124                 int policy;
125                 Interop.Elementary.elm_scroller_policy_get(Handle, IntPtr.Zero, out policy);
126                 return (ScrollBarVisiblePolicy)policy;
127             }
128             set
129             {
130                 ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
131                 Interop.Elementary.elm_scroller_policy_set(Handle, (int)h, (int)value);
132             }
133         }
134
135         public ScrollBlock ScrollBlock
136         {
137             get
138             {
139                 return (ScrollBlock)Interop.Elementary.elm_scroller_movement_block_get(Handle);
140             }
141             set
142             {
143                 Interop.Elementary.elm_scroller_movement_block_set(Handle, (int)value);
144             }
145         }
146
147         public int VerticalPageIndex
148         {
149             get
150             {
151                 int v, h;
152                 Interop.Elementary.elm_scroller_current_page_get(Handle, out h, out v);
153                 return v;
154             }
155         }
156
157         public int HorizontalPageIndex
158         {
159             get
160             {
161                 int v, h;
162                 Interop.Elementary.elm_scroller_current_page_get(Handle, out h, out v);
163                 return h;
164             }
165         }
166
167         public int VerticalPageScrollLimit
168         {
169             get
170             {
171                 int v, h;
172                 Interop.Elementary.elm_scroller_page_scroll_limit_get(Handle, out h, out v);
173                 return v;
174             }
175             set
176             {
177                 int h = HorizontalPageScrollLimit;
178                 Interop.Elementary.elm_scroller_page_scroll_limit_set(Handle, h, value);
179             }
180         }
181
182         public int HorizontalPageScrollLimit
183         {
184             get
185             {
186                 int v, h;
187                 Interop.Elementary.elm_scroller_page_scroll_limit_get(Handle, out h, out v);
188                 return h;
189             }
190             set
191             {
192                 int v = VerticalPageScrollLimit;
193                 Interop.Elementary.elm_scroller_page_scroll_limit_set(Handle, value, v);
194             }
195         }
196
197         public void SetPageSize(int width, int height)
198         {
199             Interop.Elementary.elm_scroller_page_size_set(Handle, width, height);
200         }
201
202         public void SetPageSize(double width, double height)
203         {
204             Interop.Elementary.elm_scroller_page_relative_set(Handle, width, height);
205         }
206
207         public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated)
208         {
209             if (animated)
210             {
211                 Interop.Elementary.elm_scroller_page_bring_in(Handle, horizontalPageIndex, verticalPageIndex);
212             }
213             else
214             {
215                 Interop.Elementary.elm_scroller_page_show(Handle, horizontalPageIndex, verticalPageIndex);
216             }
217         }
218
219         public void ScrollTo(Rect region, bool animated)
220         {
221             if (animated)
222             {
223                 Interop.Elementary.elm_scroller_region_bring_in(Handle, region.X, region.Y, region.Width, region.Height);
224             }
225             else
226             {
227                 Interop.Elementary.elm_scroller_region_show(Handle, region.X, region.Y, region.Width, region.Height);
228             }
229         }
230
231         protected override IntPtr CreateHandle(EvasObject parent)
232         {
233             return Interop.Elementary.elm_scroller_add(parent);
234         }
235     }
236 }