Merge remote-tracking branch 'origin/API4'
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Button.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     /// The Button is a widget that works as a clickable input element to trigger events.
23     /// </summary>
24     /// <since_tizen> preview </since_tizen>
25     public class Button : Layout
26     {
27         private SmartEvent _clicked;
28         private SmartEvent _repeated;
29         private SmartEvent _pressed;
30         private SmartEvent _released;
31
32         /// <summary>
33         /// Creates and initializes a new instance of the Button class.
34         /// </summary>
35         /// <param name="parent">
36         /// The EvasObject to which the new Button will be attached as a child.
37         /// </param>
38         /// <since_tizen> preview </since_tizen>
39         public Button(EvasObject parent) : base(parent)
40         {
41             _clicked = new SmartEvent(this, this.RealHandle, "clicked");
42             _repeated = new SmartEvent(this, this.RealHandle, "repeated");
43             _pressed = new SmartEvent(this, this.RealHandle, "pressed");
44             _released = new SmartEvent(this, this.RealHandle, "unpressed");
45
46             _clicked.On += (sender, e) =>
47             {
48                 Clicked?.Invoke(this, EventArgs.Empty);
49             };
50
51             _repeated.On += (sender, e) =>
52             {
53                 Repeated?.Invoke(this, EventArgs.Empty);
54             };
55
56             _pressed.On += (sender, e) =>
57             {
58                 Pressed?.Invoke(this, EventArgs.Empty);
59             };
60
61             _released.On += (sender, e) =>
62             {
63                 Released?.Invoke(this, EventArgs.Empty);
64             };
65         }
66
67         /// <summary>
68         /// Clicked will be triggered when the button is clicked.
69         /// </summary>
70         /// <since_tizen> preview </since_tizen>
71         public event EventHandler Clicked;
72
73         /// <summary>
74         /// Repeated will be triggered when the button is pressed without releasing it.
75         /// </summary>
76         /// <since_tizen> preview </since_tizen>
77         public event EventHandler Repeated;
78
79         /// <summary>
80         /// Pressed will be triggered when the button is pressed.
81         /// </summary>
82         /// <since_tizen> preview </since_tizen>
83         public event EventHandler Pressed;
84
85         /// <summary>
86         /// Released will be triggered when the button is released after being pressed.
87         /// </summary>
88         /// <since_tizen> preview </since_tizen>
89         public event EventHandler Released;
90
91         /// <summary>
92         /// Sets or gets the autorepeat feature of a given Bbutton.
93         /// </summary>
94         /// <remarks>
95         /// Autorepeat feature means the autorepeat event is generated when the button is kept pressed.
96         /// When set to false, no autorepeat is performed and the buttons will trigger the Clicked event when they are clicked.
97         /// When set to true, keeping a button pressed continuously will trigger the Repeated event until the button is released.
98         /// The time it takes until it starts triggering, repeated is given by AutoRepeatInitialTime,
99         /// and the time between each new emission is given by AutoRepeatGapTimeout.
100         /// </remarks>
101         /// <since_tizen> preview </since_tizen>
102         public bool AutoRepeat
103         {
104             get
105             {
106                 return Interop.Elementary.elm_button_autorepeat_get(RealHandle);
107             }
108             set
109             {
110                 Interop.Elementary.elm_button_autorepeat_set(RealHandle, value);
111             }
112         }
113
114         /// <summary>
115         /// Sets or gets the initial timeout before the Repeat event is generated.
116         /// </summary>
117         /// <since_tizen> preview </since_tizen>
118         public double AutoRepeatInitialTime
119         {
120             get
121             {
122                 return Interop.Elementary.elm_button_autorepeat_initial_timeout_get(RealHandle);
123             }
124             set
125             {
126                 Interop.Elementary.elm_button_autorepeat_initial_timeout_set(RealHandle, value);
127             }
128         }
129
130         /// <summary>
131         /// Sets or gets the interval between each generated Repeat event.
132         /// </summary>
133         /// <since_tizen> preview </since_tizen>
134         public double AutoRepeatGapTimeout
135         {
136             get
137             {
138                 return Interop.Elementary.elm_button_autorepeat_gap_timeout_get(RealHandle);
139             }
140             set
141             {
142                 Interop.Elementary.elm_button_autorepeat_gap_timeout_set(RealHandle, value);
143             }
144         }
145
146         /// <summary>
147         /// Deletes the object Color class.
148         /// </summary>
149         /// <param name="part">The Color class to be deleted.</param>
150         /// <since_tizen> preview </since_tizen>
151         [Obsolete("DeleteColorClass is obsolete, please use EdjeObject.DeleteColorClass(string)")]
152         public void DeleteColorClass(string part)
153         {
154             Interop.Elementary.edje_object_color_class_del(Handle, part);
155         }
156
157         /// <summary>
158         /// Sets or gets the BackgroundColor of a given button in the normal and pressed status.
159         /// </summary>
160         /// <since_tizen> preview </since_tizen>
161         public override Color BackgroundColor
162         {
163             set
164             {
165                 if (value.IsDefault)
166                 {
167                     EdjeObject.DeleteColorClass("button/bg");
168                     EdjeObject.DeleteColorClass("button/bg_pressed");
169                     EdjeObject.DeleteColorClass("button/bg_disabled");
170                 }
171                 else
172                 {
173                     SetPartColor("bg", value);
174                     SetPartColor("bg_pressed", value);
175                     SetPartColor("bg_disabled", value);
176                 }
177                 _backgroundColor = value;
178             }
179         }
180
181         /// <summary>
182         /// Creates a widget handle.
183         /// </summary>
184         /// <param name="parent">Parent EvasObject.</param>
185         /// <returns>Handle IntPtr.</returns>
186         /// <since_tizen> preview </since_tizen>
187         protected override IntPtr CreateHandle(EvasObject parent)
188         {
189             return Interop.Elementary.elm_button_add(parent.Handle);
190         }
191     }
192 }