add api comments for Popup3D,Popup,PopupItem,Rect,Rectangle,Scroller,Size,Slider
[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     /// <summary>
22     /// Enumeration for visible type of scrollbar.
23     /// </summary>
24     public enum ScrollBarVisiblePolicy
25     {
26         /// <summary>
27         /// Show scrollbars as needed
28         /// </summary>
29         Auto = 0,
30         /// <summary>
31         /// Always show scrollbars
32         /// </summary>
33         Visible,
34         /// <summary>
35         /// Never show scrollbars
36         /// </summary>
37         Invisible
38     }
39     /// <summary>
40     /// Enumeration for visible type of scrollbar.
41     /// </summary>
42     public enum ScrollBlock
43     {
44         /// <summary>
45         /// Scrolling movement is allowed in both direction.(X axis and Y axis)
46         /// </summary>
47         None = 1,
48         /// <summary>
49         /// Scrolling movement is not allowed in Y axis direction.
50         /// </summary>
51         Vertical = 2,
52         /// <summary>
53         /// Scrolling movement is not allowed in X axis direction.
54         /// </summary>
55         Horizontal = 4
56     }
57     /// <summary>
58     /// The Scroller is a container that holds and clips a single object and allows you to scroll across it.
59     /// </summary>
60     public class Scroller : Layout
61     {
62         SmartEvent _scroll;
63         SmartEvent _dragStart;
64         SmartEvent _dragStop;
65         SmartEvent _scrollpage;
66
67         /// <summary>
68         /// Creates and initializes a new instance of the Scroller class.
69         /// </summary>
70         /// <param name="parent">The <see cref="EvasObject"/> to which the new Scroller will be attached as a child.</param>
71         public Scroller(EvasObject parent) : base(parent)
72         {
73             _scroll = new SmartEvent(this, this.RealHandle, "scroll");
74             _dragStart = new SmartEvent(this, this.RealHandle, "scroll,drag,start");
75             _dragStop = new SmartEvent(this, this.RealHandle, "scroll,drag,stop");
76             _scrollpage = new SmartEvent(this, this.RealHandle, "scroll,page,changed");
77         }
78
79         /// <summary>
80         /// Scrolled will be triggered when the content has been scrolled.
81         /// </summary>
82         public event EventHandler Scrolled
83         {
84             add
85             {
86                 _scroll.On += value;
87             }
88             remove
89             {
90                 _scroll.On -= value;
91             }
92         }
93
94         /// <summary>
95         /// DragStart will be triggered when dragging the contents around has started.
96         /// </summary>
97         public event EventHandler DragStart
98         {
99             add
100             {
101                 _dragStart.On += value;
102             }
103             remove
104             {
105                 _dragStart.On -= value;
106             }
107         }
108
109         /// <summary>
110         /// DragStop will be triggered when dragging the contents around has stopped.
111         /// </summary>
112         public event EventHandler DragStop
113         {
114             add
115             {
116                 _dragStop.On += value;
117             }
118             remove
119             {
120                 _dragStop.On -= value;
121             }
122         }
123
124         /// <summary>
125         /// PageScrolled will be triggered when the visible page has changed.
126         /// </summary>
127         public event EventHandler PageScrolled
128         {
129             add
130             {
131                 _scrollpage.On += value;
132             }
133             remove
134             {
135                 _scrollpage.On -= value;
136             }
137         }
138
139         /// <summary>
140         /// Gets the current region in the content object that is visible through the Scroller.
141         /// </summary>
142         public Rect CurrentRegion
143         {
144             get
145             {
146                 int x, y, w, h;
147                 Interop.Elementary.elm_scroller_region_get(RealHandle, out x, out y, out w, out h);
148                 return new Rect(x, y, w, h);
149             }
150         }
151
152         /// <summary>
153         /// Sets or gets the value of HorizontalScrollBarVisiblePolicy
154         /// </summary>
155         /// <remarks>
156         /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
157         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
158         /// </remarks>
159         public ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
160         {
161             get
162             {
163                 int policy;
164                 Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero);
165                 return (ScrollBarVisiblePolicy)policy;
166             }
167             set
168             {
169                 ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
170                 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v);
171             }
172         }
173
174         /// <summary>
175         /// Sets or gets the value of VerticalScrollBarVisiblePolicy
176         /// </summary>
177         /// <remarks>
178         /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
179         /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
180         /// </remarks>
181         public ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
182         {
183             get
184             {
185                 int policy;
186                 Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy);
187                 return (ScrollBarVisiblePolicy)policy;
188             }
189             set
190             {
191                 ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
192                 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value);
193             }
194         }
195
196         /// <summary>
197         /// Sets or gets the value of ScrollBlock.
198         /// </summary>
199         /// <remarks>
200         /// This function will block scrolling movement  in a given direction.One can disable movements in the X axis, the Y axis or both.
201         /// The default value is ScrollBlock.None, where movements are allowed in both directions.
202         /// </remarks>
203         public ScrollBlock ScrollBlock
204         {
205             get
206             {
207                 return (ScrollBlock)Interop.Elementary.elm_scroller_movement_block_get(RealHandle);
208             }
209             set
210             {
211                 Interop.Elementary.elm_scroller_movement_block_set(RealHandle, (int)value);
212             }
213         }
214
215         /// <summary>
216         /// Sets or gets scroll current page number.
217         /// </summary>
218         /// <remarks>
219         /// Current page means the page which meets the top of the viewport.
220         /// If there are two or more pages in the viewport, it returns the number of the page which meets the top of the viewport.
221         /// The page number starts from 0. 0 is the first page.
222         /// </remarks>
223         public int VerticalPageIndex
224         {
225             get
226             {
227                 int v, h;
228                 Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v);
229                 return v;
230             }
231         }
232
233         /// <summary>
234         /// Sets or gets scroll current page number.
235         /// </summary>
236         /// <remarks>
237         /// Current page means the page which meets the left of the viewport.
238         /// If there are two or more pages in the viewport, it returns the number of the page which meets the left of the viewport.
239         /// The page number starts from 0. 0 is the first page.
240         /// </remarks>
241         public int HorizontalPageIndex
242         {
243             get
244             {
245                 int v, h;
246                 Interop.Elementary.elm_scroller_current_page_get(RealHandle, out h, out v);
247                 return h;
248             }
249         }
250
251         /// <summary>
252         /// Sets or gets the maximum limit of the movable page at vertical direction.
253         /// </summary>
254         public int VerticalPageScrollLimit
255         {
256             get
257             {
258                 int v, h;
259                 Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v);
260                 return v;
261             }
262             set
263             {
264                 int h = HorizontalPageScrollLimit;
265                 Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, h, value);
266             }
267         }
268
269         /// <summary>
270         /// Sets or gets the maximum limit of the movable page at horizontal direction.
271         /// </summary>
272         public int HorizontalPageScrollLimit
273         {
274             get
275             {
276                 int v, h;
277                 Interop.Elementary.elm_scroller_page_scroll_limit_get(RealHandle, out h, out v);
278                 return h;
279             }
280             set
281             {
282                 int v = VerticalPageScrollLimit;
283                 Interop.Elementary.elm_scroller_page_scroll_limit_set(RealHandle, value, v);
284             }
285         }
286
287         /// <summary>
288         /// Sets the page size to an absolute fixed value, with 0 turning it off for that axis.
289         /// </summary>
290         /// <param name="width">The horizontal page size.</param>
291         /// <param name="height">The vertical page size.</param>
292         public void SetPageSize(int width, int height)
293         {
294             Interop.Elementary.elm_scroller_page_size_set(RealHandle, width, height);
295         }
296
297         /// <summary>
298         /// Sets the scroll page size relative to the viewport size.
299         /// </summary>
300         /// <remarks>
301         /// The scroller is capable of limiting scrolling by the user to "pages".
302         /// That is to jump by and only show a "whole page" at a time as if the continuous area of the scroller
303         /// content is split into page sized pieces. This sets the size of a page relative to the viewport of the scroller.
304         /// 1.0 is "1 viewport" which is the size (horizontally or vertically). 0.0 turns it off in that axis.
305         /// This is mutually exclusive with the page size (see elm_scroller_page_size_set() for more information).
306         /// Likewise 0.5 is "half a viewport". Usable values are normally between 0.0 and 1.0 including 1.0.
307         /// If you only want 1 axis to be page "limited", use 0.0 for the other axis.
308         /// </remarks>
309         /// <param name="width">The horizontal page relative size.</param>
310         /// <param name="height">The vertical page relative size.</param>
311         public void SetPageSize(double width, double height)
312         {
313             Interop.Elementary.elm_scroller_page_relative_set(RealHandle, width, height);
314         }
315
316         /// <summary>
317         /// Shows a specific virtual region within the scroller content object by the page number.
318         /// (0, 0) of the indicated page is located at the top-left corner of the viewport.
319         /// </summary>
320         /// <param name="horizontalPageIndex">The horizontal page number.</param>
321         /// <param name="verticalPageIndex">The vertical page number.</param>
322         /// <param name="animated">True means slider with animation.</param>
323         public void ScrollTo(int horizontalPageIndex, int verticalPageIndex, bool animated)
324         {
325             if (animated)
326             {
327                 Interop.Elementary.elm_scroller_page_bring_in(RealHandle, horizontalPageIndex, verticalPageIndex);
328             }
329             else
330             {
331                 Interop.Elementary.elm_scroller_page_show(RealHandle, horizontalPageIndex, verticalPageIndex);
332             }
333         }
334
335         /// <summary>
336         /// Shows a specific virtual region within the scroller content object.
337         /// </summary>
338         /// <remarks>
339         /// This ensures that all (or part, if it does not fit) of the designated region in the virtual content object ((0, 0)
340         /// starting at the top-left of the virtual content object) is shown within the scroller.
341         /// If set "animated" to true, it will allows the scroller to "smoothly slide" to this location
342         /// (if configuration in general calls for transitions).
343         /// It may not jump immediately to the new location and may take a while and show other content along the way.
344         /// </remarks>
345         /// <param name="region">Rect struct of region.</param>
346         /// <param name="animated">True means allows the scroller to "smoothly slide" to this location.</param>
347         public void ScrollTo(Rect region, bool animated)
348         {
349             if (animated)
350             {
351                 Interop.Elementary.elm_scroller_region_bring_in(RealHandle, region.X, region.Y, region.Width, region.Height);
352             }
353             else
354             {
355                 Interop.Elementary.elm_scroller_region_show(RealHandle, region.X, region.Y, region.Width, region.Height);
356             }
357         }
358
359         protected override IntPtr CreateHandle(EvasObject parent)
360         {
361             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
362             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
363
364             RealHandle = Interop.Elementary.elm_scroller_add(handle);
365             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
366
367             return handle;
368         }
369     }
370 }