dec0c586809120aab88e20ec5212c228815d9bf4
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Radio.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 Radio : Layout
22     {
23         SmartEvent _changed;
24
25         public Radio(EvasObject parent) : base(parent)
26         {
27             _changed = new SmartEvent(this, this.RealHandle, "changed");
28             _changed.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
29         }
30
31         public event EventHandler ValueChanged;
32
33         public int StateValue
34         {
35             get
36             {
37                 return Interop.Elementary.elm_radio_state_value_get(RealHandle);
38             }
39             set
40             {
41                 Interop.Elementary.elm_radio_state_value_set(RealHandle, value);
42             }
43         }
44
45         public int GroupValue
46         {
47             get
48             {
49                 return Interop.Elementary.elm_radio_value_get(RealHandle);
50             }
51             set
52             {
53                 Interop.Elementary.elm_radio_value_set(RealHandle, value);
54             }
55         }
56
57         public void SetGroup(Radio group)
58         {
59             if (group == null)
60             {
61                 throw new ArgumentNullException("group");
62             }
63             Interop.Elementary.elm_radio_group_add(RealHandle, group.RealHandle);
64         }
65
66         protected override IntPtr CreateHandle(EvasObject parent)
67         {
68             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
69             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
70
71             RealHandle = Interop.Elementary.elm_radio_add(handle);
72             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
73
74             return handle;
75         }
76     }
77 }