302bdf92728161bef71bf12905b011eb7a668820
[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     public class Button : Layout
22     {
23         private SmartEvent _clicked;
24         private SmartEvent _repeated;
25         private SmartEvent _pressed;
26         private SmartEvent _released;
27
28         public Button(EvasObject parent) : base(parent)
29         {
30             _clicked = new SmartEvent(this, this.RealHandle, "clicked");
31             _repeated = new SmartEvent(this, this.RealHandle, "repeated");
32             _pressed = new SmartEvent(this, this.RealHandle, "pressed");
33             _released = new SmartEvent(this, this.RealHandle, "unpressed");
34
35             _clicked.On += (sender, e) =>
36             {
37                 Clicked?.Invoke(this, EventArgs.Empty);
38             };
39
40             _repeated.On += (sender, e) =>
41             {
42                 Repeated?.Invoke(this, EventArgs.Empty);
43             };
44
45             _pressed.On += (sender, e) =>
46             {
47                 Pressed?.Invoke(this, EventArgs.Empty);
48             };
49
50             _released.On += (sender, e) =>
51             {
52                 Released?.Invoke(this, EventArgs.Empty);
53             };
54         }
55
56         public event EventHandler Clicked;
57
58         public event EventHandler Repeated;
59
60         public event EventHandler Pressed;
61
62         public event EventHandler Released;
63
64         public bool AutoRepeat
65         {
66             get
67             {
68                 return !Interop.Elementary.elm_button_autorepeat_get(RealHandle);
69             }
70             set
71             {
72                 Interop.Elementary.elm_button_autorepeat_set(RealHandle, value);
73             }
74         }
75
76         public double AutoRepeatInitialTime
77         {
78             get
79             {
80                 return Interop.Elementary.elm_button_autorepeat_initial_timeout_get(RealHandle);
81             }
82             set
83             {
84                 Interop.Elementary.elm_button_autorepeat_initial_timeout_set(RealHandle, value);
85             }
86         }
87
88         public double AutoRepeatGapTimeout
89         {
90             get
91             {
92                 return Interop.Elementary.elm_button_autorepeat_gap_timeout_get(RealHandle);
93             }
94             set
95             {
96                 Interop.Elementary.elm_button_autorepeat_gap_timeout_set(RealHandle, value);
97             }
98         }
99
100         [Obsolete("DeleteColorClass is obsolete, please use EdjeObject.DeleteColorClass(string)")]
101         public void DeleteColorClass(string part)
102         {
103             Interop.Elementary.edje_object_color_class_del(Handle, part);
104         }
105
106         public override Color BackgroundColor
107         {
108             set
109             {
110                 if (value.IsDefault)
111                 {
112                     EdjeObject.DeleteColorClass("button/bg");
113                     EdjeObject.DeleteColorClass("button/bg_pressed");
114                 }
115                 else
116                 {
117                     SetPartColor("bg", value);
118                     SetPartColor("bg_pressed", value);
119                 }
120                 _backgroundColor = value;
121             }
122         }
123
124         protected override IntPtr CreateHandle(EvasObject parent)
125         {
126             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
127             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
128
129             RealHandle = Interop.Elementary.elm_button_add(handle);
130             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
131
132             return handle;
133         }
134     }
135 }