[ElmSharp] Mark ElmSharp API as API Level: preview
[platform/core/csapi/tizenfx.git] / src / ElmSharp.Wearable / ElmSharp.Wearable / MoreOption.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.Collections.Generic;
19 using System.Linq;
20
21 namespace ElmSharp.Wearable
22 {
23     /// <summary>
24     /// The MoreOption is a widget composed of the toggle(cue button) and more option view, and MoreOption can change a visibility through the toggle.
25     /// Inherits Layout
26     /// </summary>
27     /// <since_tizen> preview </since_tizen>
28     public class MoreOption : Layout
29     {
30         /// <summary>
31         /// Sets or gets the list of more option item
32         /// </summary>
33         /// <since_tizen> preview </since_tizen>
34         public IList<MoreOptionItem> Items { get; private set; }
35
36         /// <summary>
37         /// Selected will be triggered when the user selects an item.
38         /// </summary>
39         /// <since_tizen> preview </since_tizen>
40         public event EventHandler<MoreOptionItemEventArgs> Selected;
41         /// <summary>
42         /// Clicked will be triggered when the user selects the already selected item again or selects a selector.
43         /// </summary>
44         /// <since_tizen> preview </since_tizen>
45         public event EventHandler<MoreOptionItemEventArgs> Clicked;
46         /// <summary>
47         /// Opened will be triggered when more option view is shown.
48         /// </summary>
49         /// <since_tizen> preview </since_tizen>
50         public event EventHandler Opened;
51         /// <summary>
52         /// Closed will be triggered when more option view is hidden.
53         /// </summary>
54         /// <since_tizen> preview </since_tizen>
55         public event EventHandler Closed;
56
57         SmartEvent<PointerEventArgs> _selectedEvent;
58         SmartEvent<PointerEventArgs> _clickedEvent;
59         SmartEvent _openedEvent;
60         SmartEvent _closedEvent;
61
62         /// <summary>
63         /// Creates and initializes a new instance of MoreOption class.
64         /// </summary>
65         /// <param name="parent">The parent is a given container which will be attached by MoreOption as a child. It's <see cref="EvasObject"/> type.</param>
66         /// <since_tizen> preview </since_tizen>
67         public MoreOption(EvasObject parent) : base(parent)
68         {
69             Items = new MoreOptionList(this);
70
71             _selectedEvent = new SmartEvent<PointerEventArgs>(this, "item,selected", (d, o, info) => new PointerEventArgs { Pointer = info });
72             _clickedEvent = new SmartEvent<PointerEventArgs>(this, "item,clicked", (d, o, info) => new PointerEventArgs { Pointer = info });
73             _openedEvent = new SmartEvent(this, "more,option,opened");
74             _closedEvent = new SmartEvent(this, "more,option,closed");
75
76             _selectedEvent.On += (s, e) =>
77             {
78                 MoreOptionItem selected = Items.FirstOrDefault(i => i.Handle == e.Pointer);
79                 Selected?.Invoke(this, new MoreOptionItemEventArgs() { Item = selected });
80             };
81
82             _clickedEvent.On += (s, e) =>
83             {
84                 MoreOptionItem selected = Items.FirstOrDefault(i => i.Handle == e.Pointer);
85                 Clicked?.Invoke(this, new MoreOptionItemEventArgs() { Item = selected });
86             };
87
88             _openedEvent.On += (s, e) => Opened?.Invoke(this, EventArgs.Empty);
89             _closedEvent.On += (s, e) => Closed?.Invoke(this, EventArgs.Empty);
90
91         }
92
93         /// <summary>
94         /// Creates a widget handle.
95         /// </summary>
96         /// <param name="parent">Parent EvasObject</param>
97         /// <returns>Handle IntPtr</returns>
98         /// <since_tizen> preview </since_tizen>
99         protected override IntPtr CreateHandle(EvasObject parent)
100         {
101             return Interop.Eext.eext_more_option_add(parent);
102         }
103
104         /// <summary>
105         /// Sets or gets the direction of more option.
106         /// </summary>
107         /// <since_tizen> preview </since_tizen>
108         public MoreOptionDirection Direction
109         {
110             get
111             {
112                 int dir = Interop.Eext.eext_more_option_direction_get(this);
113                 return (MoreOptionDirection)dir;
114             }
115
116             set
117             {
118                 Interop.Eext.eext_more_option_direction_set(this, (int)value);
119             }
120         }
121
122         /// <summary>
123         /// Sets or gets the visibility of more option view.
124         /// </summary>
125         /// <since_tizen> preview </since_tizen>
126         public bool IsOpened
127         {
128             get
129             {
130                 return Interop.Eext.eext_more_option_opened_get(this);
131             }
132
133             set
134             {
135                 Interop.Eext.eext_more_option_opened_set(this, value);
136             }
137         }
138     }
139
140     /// <summary>
141     /// Enumeration for More Option Direction type.
142     /// </summary>
143     /// <since_tizen> preview </since_tizen>
144     public enum MoreOptionDirection
145     {
146         /// <summary>
147         /// Top direction
148         /// </summary>
149         Top,
150         /// <summary>
151         /// Bottom direction
152         /// </summary>
153         Bottom,
154         /// <summary>
155         /// Left direction
156         /// </summary>
157         Left,
158         /// <summary>
159         /// Right direction
160         /// </summary>
161         Right
162     }
163 }